Python Forum
While loops - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: While loops (/thread-5162.html)



While loops - ralfi - Sep-21-2017

List = ["1","2","3","5" ]
while True:
print("hello")
number = (int(input("give me a number? ")
if i % 2 = 0:
print(L)
File "<ipython-input-3-4bed4d992b03>", line 5
if i % 2 = 0:
^
SyntaxError: invalid syntax


I want the code to add an even number to the list if the user inputs an even number.


RE: While loops - Lux - Sep-21-2017

There's an error in your 'if' statement- when comparing a variable or expression to something else, use === is the assignment operator, meaning it's just used to set values of variables.


RE: While loops - ralfi - Sep-21-2017

List = ["1","2","3","5" ]
while True:
print("hello")
number = (int(input("give me a number? ")
if number % 2 == 0:
print(List)
File "<ipython-input-4-31e1ba2ca82e>", line 5
if number % 2 == 0:
^
SyntaxError: invalid syntax

== did nothing still invalid syntax


RE: While loops - ichabod801 - Sep-21-2017

You're missing parens at the end of line four. Please use python tags to post your code. See the BBCode link in my signature (below) for instructions.


RE: While loops - nilamo - Sep-22-2017

(Sep-21-2017, 03:15 AM)ralfi Wrote:
List = ["1","2","3","5" ]
while True:
print("hello")
number = (int(input("give me a number? ")
         ^   ^     ^                    ^

 You open three parenthesis, but only close one of them. A statement is illegal inside of parentheses, which is why you get a syntax error pointing at the if statement you try to include inside the parentheses.