Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
While loops
#1
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.
Reply
#2
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.
Reply
#3
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
Reply
#4
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
(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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020