+ 2

Help me please!

Hello, I'm beginner. what does this mean x += 1 ? x = 1 while x < 10: if x%2 == 0: print(str(x) + " is even") else: print(str(x) + " is odd") x += 1

12th Feb 2021, 6:45 PM
Emily
Emily - avatar
9 Antworten
+ 4
Jayakrishna🇮🇳 you're absolutely correct. I missed the fact that the question was about Python code. Thanks.
12th Feb 2021, 8:53 PM
Sonic
Sonic - avatar
+ 3
If am not wrong, it don't work in python Sonic No unary ++/-- operators in python
12th Feb 2021, 8:50 PM
Jayakrishna 🇮🇳
+ 3
Emily disregard my previous answer about x++. That's a syntax used in other languages like C/C++, Java and others but not Python.
12th Feb 2021, 8:54 PM
Sonic
Sonic - avatar
+ 2
Short form of x=x+1 is x+=1. Using there in loop to increment x value from x=1 to x=10 When x<10 becomes false ,loop gets terminated...
12th Feb 2021, 6:51 PM
Jayakrishna 🇮🇳
+ 2
Another way to write it is x++
12th Feb 2021, 8:47 PM
Sonic
Sonic - avatar
0
In this code, u are separating the numbers into odds and evens between 1-10. U have initially started from 1 and the code checks are less than 10 or not then continues. x+=1 represents increment the number to one as x=1, the next number would be 2. You can also use x++ if u are confusing with that.
15th Feb 2021, 12:03 PM
Kalyan Sai
Kalyan Sai - avatar