problem in the excersice
why it gives me that the syntax is invalid
Create a while loop that will print all odd numbers from 0 to 30 on the same row.
*Hint: There are two ways in which you can create the odd values!*
x = 0
while x % 2 = 1:
print (x, end = " ")
x <= 30
1 answers ( 0 marked as helpful)
Thanks for reaching out.
This is because the single equal sign (
=) is used for assigning a value to a variable and when you want to compare some values you should use the double equal sign (
It seems that you want to print all odd numbers from 1 to 30. Please, use the following code:
x = 0
while x <= 30:
if x % 2 == 1:
print(x, end = " ")
x += 1
Hope this helps.