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

3rd May 2021, 9:16 AM
Faiq Ali
Faiq Ali - avatar
2 Respuestas
+ 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!
3rd May 2021, 9:29 AM
Lothar
Lothar - avatar
+ 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
3rd May 2021, 9:30 AM
Rik Wittkopp
Rik Wittkopp - avatar