Last answered:

29 Nov 2022

Posted on:

20 Nov 2022

0

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.
<br />
*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)
Instructor
Posted on:

29 Nov 2022

0

Hi Yousof!
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.
Best,
Tsvetelin

Submit an answer