Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
need help, newbie in town.
#1
Ok I need help. I can't find the issue with this code
>>> def main():
celsius=eval(input("What's the Celsius temperature" ))

fahrenheit=9/5*celsius+32
print("The fahrenheit temperature is "fahrenheit)



This is a simple converter, I'm just practicing around by reading a guide that I have. But for some reason I get a syntax error message when I 'print' Fahrenheit(the last line). Can someone explain me why? what am I doing wrong?
Reply
#2
>>> indicates that you are using a command line interpreter.
You must type (or paste)
lines one at a time (with eol) in this mode, keeping proper indentation:
In addition, you do not need nor want the eval statement you wan integer conversion instead
ending up with:
>>> def main():
...     celsius = int(input("What's the Celsius temperature "))
...     fahrenheit = (9 / 5) * celsius + 32
...     print("The fahrenheit temperature is {}".format(fahrenheit))
...
>>> main()
What's the Celsius temperature 25
The fahrenheit temperature is 77.0
>>>
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] [Nominatim] How to get "town" from reply? Winfried 0 1,925 Aug-27-2018, 05:36 AM
Last Post: Winfried

Forum Jump:

User Panel Messages

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