Fahrenheit to Celsius and vice versa

This is the place for queries that don't fit in any of the other categories.

Fahrenheit to Celsius and vice versa

Postby sonofeast11 » Sun May 18, 2014 10:25 pm

This is the code I have typed for a Fahrenheit to Celsius and vice versa program. The error says that: 'str' object is not callable.
What have I done wrong?


Code: Select all
Type = str(input(" Are you currently using Fahrenheit or Celsius?\n"))
Int = int(input(" What is the temperature?\n"))

if Type == "Fahrenheit":
    print("The temperature in celsius is,"((Int - 32) * 5/9))

else:
    print("The temperature in fahrenheit is,"(Int * (9/5 + 32)))
Last edited by micseydel on Sun May 18, 2014 11:09 pm, edited 1 time in total.
Reason: Code tags, lock.
sonofeast11
 
Posts: 4
Joined: Sun May 18, 2014 4:20 pm

Re: Fahrenheit to Celsius and vice versa

Postby micseydel » Sun May 18, 2014 11:19 pm

You have two places in your code where you have a quote character next to an open parenthesis. You need to put a comma between them as a separate, because if you don't, the parenthesis are treated as the function-call operator and the Python strings are interpreted as if they were functions.

Also, in the future, always include your full traceback verbatim, you'll likely save us a great deal of time helping you. In a case like this, hard-coding input variables so long as the problem is reproducible is always advantageous, since in this case it was reproducible either branch, and the code short and simple enough to understand, that is not always the case.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1260
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Fahrenheit to Celsius and vice versa

Postby sonofeast11 » Mon May 19, 2014 2:53 pm

Thank you! There was also an error with the order of operations but i've figured that out.
Again, Thanks!
sonofeast11
 
Posts: 4
Joined: Sun May 18, 2014 4:20 pm

Re: Fahrenheit to Celsius and vice versa

Postby mnutz » Mon May 19, 2014 8:51 pm

just an idea, but to make things easier for the user why not stop them from having to write our Fahrenheit or Celcius?

Also, I'd add in a 'catch all' if they enter the incorrect letter, and use a float instead of a whole number depending on how accurate the user wants to be :)

Code: Select all
Type = str(input("If you are using Fahrenheit press F, or press C if you are using Celsius?\n"))
temp = float(input(" What is the temperature?\n"))

if Type == "f":
    print("The temperature in celsius is,"((temp - 32) * 5/9))
elif Type == "c":
    print("The temperature in fahrenheit is,"(temp * (9/5 + 32)))
else:
    print("Sorry, you have not entered a correct measurement.")
mnutz
 
Posts: 10
Joined: Sun Nov 17, 2013 8:11 am


Return to General Coding Help

Who is online

Users browsing this forum: cnitin, W3C [Linkcheck] and 4 guests