0

while loop (python)

why doesn't it work? def main (): inputmyarray = [9,8,7,6,5,4,3,2] ; number = len(inputmyarray) i = 0 ; while i < number: print (inputmyarray[i]) ++i ; if __name__ == '__main__': main() ;

3rd Jun 2017, 2:12 PM
Navid Tak
Navid Tak - avatar
2 Respuestas
+ 6
@Justin Hill: In Python semi-colon ( ; ) is not mandatory, but it's allowed (required in case of multi instruction on a single line)... The only error in the code quoted in question is the use of ++i wich isn't effectively not allowed in Python and need to be replaced by either i += 1 or i = i + 1 ^^
3rd Jun 2017, 3:00 PM
visph
visph - avatar
0
Python doesn't use ; .. It also doesn't use ++.. remove the ; and change ++i to i+=1 *Visph is correct about ( ; ) .. Python doesn't mind them, but they aren't necessary. Still, ending specific things in ( ; ) is a good habit to get into
3rd Jun 2017, 2:26 PM
LordHill
LordHill - avatar