Reputation: 3
So I'm fairly new to programming and I'm just paying around trying to make some programs. This one is self-explanatory, but why do I get an invalid syntax for 'print' in line 12 (the first 'elif' statement)?
while True:
temp = raw_input("Would you like to convert:\nCelsius to Fahrenheit (press 1)\nor\nFahrenheit to Celsius (press 2)\n")
if temp == 1:
celsius = raw_input("What is the temperature in degrees Celsius?")
tempFahr = ((int(celsius)*(9/5))+32)
print "When it is " + celsius + " degrees celsius, it is " + tempFahr + "degrees fahrenheit."
elif temp == 2:
fahrenheit = raw_input("What is the temperature in degrees Fahrenheit?")
tempCel = ((int(fahrenheit)-32)*(5/9)
print "When it is " + fahrenheit + " degrees fahrenheit, it is " + tempCel + "degress celsius."
elif temp = 42:
print "You're a winner!"
else:
print "That is not a valid option."
print "Press 'enter' to input another value"
raw_input()
Also, if I over complicated something, I would really appreciate if you could point out what it was. Try not to correct me too much, though, I would like to try and figure it out on my own.
Upvotes: 0
Views: 1176
Reputation: 681
you should try
print("When it is " + str(fahrenheit) + " degrees fahrenheit, it is " + str(tempCel) + " degress celsius.")
Upvotes: 0
Reputation: 353569
There are two syntax errors. First, you forgot a closing )
in the tempCel
line, which confuses Python about the next print
:
tempCel = ((int(fahrenheit)-32)*(5/9)
print "When it is " + fahrenheit + " degrees fahrenheit, it is " + tempCel + "degress celsius."
Then you used =
where you meant ==
:
elif temp = 42:
There are other errors -- for example, you're comparing temp
, which is a string, to 1
and 2
, which are integers, and you also might want to type 5/9
at the console to see what it gives you -- but they're not SyntaxError
s.
Upvotes: 1