You are given a program that outputs all the numbers from 0 to 10. Change the code to make it output only the even numbers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

You are given a program that outputs all the numbers from 0 to 10. Change the code to make it output only the even numbers

x = 0 while x<=10: if (x % 2 = 0) print(x) x += 1 This is my code but it keeps on outputting 0

19th Jan 2021, 3:02 PM
NWACHUKWU PRECIOUS CALEB
NWACHUKWU PRECIOUS CALEB - avatar
13 Answers
+ 10
= is used for assignment of variables and values == is used for comparisons And also keep in mind the indentions and colons after if conditions. if (x % 2 == 0): print(x)
19th Jan 2021, 3:04 PM
noteve
noteve - avatar
+ 9
NWACHUKWU PRECIOUS CALEB There should be == not = x = 0 while x <= 10: if x % 2 == 0: print(x) x += 1
19th Jan 2021, 3:03 PM
AอขJ
AอขJ - avatar
+ 6
(syntax error) you use == Code: x = 0 while x <= 10: if x % 2 == 0: print(x) x += 1
19th Jan 2021, 3:10 PM
NGUYEN THANH TUNG
NGUYEN THANH TUNG - avatar
+ 2
Change the = to == in the 3rd line. = is an assignment operator
21st Jan 2021, 5:29 AM
โˆ†BHโˆ†Y
โˆ†BHโˆ†Y - avatar
+ 1
x = 0 while x<=10: if (x % 2 == 0): print(x) x += 1 The if statement needed a : at the end of the parenthesis. Indented everything correctly and the code worked for the solution.
14th Jan 2022, 6:06 PM
Jason Walker
Jason Walker - avatar
0
x = 0 while x <= 10: if x % 2 == 0: print(x) x += 1 make sure about the indentations that will provide you the error for this
18th May 2021, 6:42 AM
Mohammed Ebrahim
Mohammed Ebrahim - avatar
0
X=0 While x<=10: If x % 2==0: Print(x) What do I do next?
11th Nov 2021, 4:42 PM
joanna Godfrey
0
You are given a program that outputs all the numbers from 0 to 10. Change the code to make it output only the even numbers. Solve immediately
12th Feb 2022, 2:10 PM
Nikhil More
0
x = 0 while x <= 10: if x%2 == 0: print(str(x)) x += 1
21st Feb 2022, 10:55 AM
Shaik Mohammed Shumayl
0
x = 0 while x <= 10: if x % 2 == 0: print(x) x += 1
3rd Mar 2022, 3:01 PM
Nikhila
0
Here is the correct answer x = 0 while x<=10: if x%2== 0: print(x) x+=1
25th Mar 2022, 2:05 AM
Manikandan Dhandapani
- 1
correct answer x = 0 while x<=10: print(x) x += 2
26th Jan 2022, 2:21 PM
Riad Kaptan
- 1
x = 0 while x<=10: print(x) x+=10 x-=8
15th Mar 2022, 6:17 AM
python๐Ÿ๐Ÿ๐Ÿ’ป
python๐Ÿ๐Ÿ๐Ÿ’ป - avatar