Wants to implement/convert js to python,, the main issue is with the for loop; (can't iterate integer) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

Wants to implement/convert js to python,, the main issue is with the for loop; (can't iterate integer)

function solution(P, C){ let counter = 0; for(let x = 0; x < C; x++){ if( P > 1){ counter +=1; } P -= 2; } return "You can play: "+counter; } console.log(solution(102,102));

13th Jun 2019, 1:05 PM
abdulconsole
abdulconsole - avatar
2 Answers
+ 6
~ swim ~ thanks mahn, while loop worked. def solution(P, C): counter = 0 x = 0 while x <= C: if P > 1: counter+=1 P-=2 x+=1 print "You can play: ",counter solution(102,102)
13th Jun 2019, 2:19 PM
abdulconsole
abdulconsole - avatar
+ 4
I'm pretty sure you can shared the wrong code, because iteration problems only show up with enhanced for loops
13th Jun 2019, 1:33 PM
Airree
Airree - avatar