Python Forum

Full Version: While loops
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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.
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
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.
(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.