Help me please! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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
8 Answers
+ 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
+ 2
Emily It is a short form of x = x+1 You can write x = x+1, it's your choice but writing x += 1 is much shorter and saves time
13th Feb 2021, 2:59 AM
∆BH∆Y
∆BH∆Y - avatar
+ 1
Sandra S please post it as a seperate question so that we may be able to help you out with it
13th Feb 2021, 10:56 AM
∆BH∆Y
∆BH∆Y - 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