0
print('Hello world!') x = 1 while x < 10: if x%2 == 0: print(str(x) + " is even") else: print(str(x) + " is odd")
I cannot understand what is this .i am new in coding
2 odpowiedzi
+ 3
Faiq Ali ,
this code is incomplete, it produces an infinite loop. to solve this, x has to be incremented in each loop iteration.
▪︎in general this code gets a number x, checks whether it is odd or even and print out the respectivecmessage
may be you need a bit more time and experience to understand this code. be patient, continue learning or repeat some parts of the tutorial, and practice as much as you can do. so you will understand step by step what this code is doing.
happy coding and good success!
+ 1
As it is presented, it will print Hello World, then it will print an infinite amount of lines stating that 1 is odd.
This is because the while loop does not have an exit, so will continue to repeat.
Try this instead to see if it help you understand while, if, else & %
print('Hello world!')
x = 1
while x < 10:
if x%2 == 0:
print(str(x) + " is even")
else:
print(str(x) + " is odd")
x +=1