Bottom Page

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.
Quote
#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.
Quote
#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
Quote
#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

Quote
#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.
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)