I got a confusing problem with my temperature converting program in Python, confusing for me at least since I'm new to this. I got two locations, Germany and USA, one country that the user is from and where the user is currently at. I'm just trying to convert the temperature from the temperature scale in the country the user is currently in, to the temperature scale to the country that the user is coming from.
For example, the user is from Germany but currently in the USA. So in that case I want the program to take the temperature the user is typing in to be converted from Celsius to Fahrenheit.
My code:
location = input("Where are you from?")
us = ("USA")
ger = ("Germany")
if location == ger:
print("You are from Germany")
elif location == us:
print("You are from the USA")
else:
print("Enter the country Germany or USA")
recentLoc = input("What is your location right now?")
if recentLoc == ger:
print("You are in Germany right now")
elif recentLoc == us:
print("You are in the USA right now")
else:
print("Please enter the country Germany or the USA")
temp = input("What is the temperature outdoor tomorrow?")
def convert_f():
f = float(fahrenheit)
f = (temp*9/5)+32
return(f)
def convert_c():
c = float(celsius)
c = (temp-32)*5/9
return(c)
if recentLoc == ger and location == us:
print("Temperature for tomorrow is " + float(c) + "Celsius or " + float(f) + "Fahrenheit")
elif recentLoc == us and location == ger:
print("Temperature for tomorrow is " + float(f) + "Fahrenheit or " + float(c) + "Celsius")
elif recentLoc == us and location == us:
print("Temperature for tomorrow is " + float(f) + "Fahrenheit")
elif recentLoc == ger and location == ger:
print("Temperature for tomorrow is " + float(c) + "Celsius")
else:
print("Please type in a number")
Error message:
NameError: name 'f' is not defined