Pages: 1
Topic closed
number1 = raw_input("Please enter first number") op = (raw_input("Please enter an operator, either x, +, - or /.")) number2 = (raw_input("Please enter a second number")) print number1+operator+number2 if op == * print number1*number2 elif op == + print number1+number2 elif op == - print number1-number2 elif op == / print number1/number2 else print "operator is not valid"
It says that there is an invalid syntax
if op == * ^ SyntaxError : invalid syntax
Offline
I don't know any python at all but this would be my guess:
Isn't * part of a string? Imo you should treat it like a string :3
edit: you should ask on Coders' Shed
Last edited by slinger (2012-04-17 03:34:10)
Offline
slinger wrote:
I don't know any python at all but this would be my guess:
Isn't * part of a string? Imo you should treat it like a string :3
edit: you should ask on Coders' Shed
Yep, i was just going to say, it looks like a string.
number1 = raw_input("Please enter first number") op = raw_input("Please enter an operator, either x, +, - or /.") number2 = raw_input("Please enter a second number") print number1+operator+number2 if op == "*" print number1*number2 elif op == "+" print number1+number2 elif op == "-" print number1-number2 elif op == "/" print number1/number2 else print "operator is not valid"
And are you sure the else if command is "elif"?
Offline
you need to import antigravity
Offline
GameHutSoftware wrote:
you need to import antigravity
What does some antigravity library have to do with it? The syntax error was not stringing.
Offline
number1 = raw_input("Please enter first number") op = (raw_input("Please enter an operator, either x, +, - or /.")) number2 = (raw_input("Please enter a second number")) print number1 + operator + number2 if op == '*': print number1 * number2 elif op == '+': print number1 + number2 elif op == '-': print number1 - number2 elif op == '/': print number1 / number2 else: print "operator is not valid"
three things:
you should put '' or "" around strings
you should put ':' after compound statements
you should put space around operators (and read PEP8 when you have time)
good luck!
Offline
scimonster wrote:
GameHutSoftware wrote:
you need to import antigravity
What does some antigravity library have to do with it? The syntax error was not stringing.
just do it
Offline
scimonster wrote:
slinger wrote:
I don't know any python at all but this would be my guess:
Isn't * part of a string? Imo you should treat it like a string :3
edit: you should ask on Coders' ShedYep, i was just going to say, it looks like a string.
Code:
number1 = raw_input("Please enter first number") op = raw_input("Please enter an operator, either x, +, - or /.") number2 = raw_input("Please enter a second number") print number1+operator+number2 if op == "*" print number1*number2 elif op == "+" print number1+number2 elif op == "-" print number1-number2 elif op == "/" print number1/number2 else print "operator is not valid"And are you sure the else if command is "elif"?
Yes, 'else if' is 'elif' in Python.
Offline
GameHutSoftware wrote:
scimonster wrote:
GameHutSoftware wrote:
you need to import antigravity
What does some antigravity library have to do with it? The syntax error was not stringing.
just do it
Um, why? I've got no idea what Antigravity is in Python, but I've never had problems.
Offline
A variable cannot be an operator in python. It makes it confused.
EDIT: Wouldn't it make more sense to use a function in the end instead of that jumble of 'if's?
Last edited by -GizzardGulp- (2012-04-21 10:49:35)
Offline
maxskywalker wrote:
GameHutSoftware wrote:
scimonster wrote:
What does some antigravity library have to do with it? The syntax error was not stringing.just do it
Um, why? I've got no idea what Antigravity is in Python, but I've never had problems.
I just tried it and it opened https://xkcd.com/353/.
That's funny. xD
Offline
Update it to Python 3 while you're at it.
Offline
Topic closed
Pages: 1