Получих объркващ проблем с моята програма за преобразуване на температура в Python, объркващ поне за мен, тъй като съм нов в това. Имам две местоположения, Германия и САЩ, една държава, от която е потребителят и където се намира потребителят в момента. Просто се опитвам да преобразувам температурата от температурната скала в страната, в която потребителят се намира в момента, в температурната скала на страната, от която идва потребителят.
Например, потребителят е от Германия, но в момента е в САЩ. Така че в този случай искам програмата да вземе температурата, която потребителят въвежда, за да бъде преобразувана от Целзий във Фаренхайт.
Моят код:
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")
Съобщение за грешка:
NameError: name 'f' is not defined
f
? - person Peter Wood   schedule 20.09.2018