我正在尝试创建一个函数,我将在其中存储转换器的公式。当需要 X 公式时,它会被调用。当使用简单的0:a+b尝试它 时,它在返回时起作用,但是当尝试将其存储为字符串meter_to_foots 时,它不起作用。我需要将该公式存储为某种东西,因为我需要稍后输出它。这是我遇到问题的代码的一部分。NameError:未定义名称“meters_input”
def my_formulas(i):
switcher={
0:(meters_input/0.3048)
}
return switcher.get(i,"Invalid formula")
distance_pick=input("Please pick one of the current convertions : \n \n1.Meters to X \n2.Inches to X \n3.Feets to X ")
if(distance_pick=="1"):
cls()
distance_choice = input ("Please select which converter would you like to use ! : \n \n1.Meter to Foot \n2.Meter to Yard \n3.Meters to Inches ")
if(distance_choice=="1"):
meters_input=float(input("Make sure to enter distance in Meters ! : "))
my_formulas(0)
print ("\nYou entered", meters_input , "meters, which is equal to",my_formulas(0),"foots.")
time.sleep (3)
cls ()
read_carefully_message()
慕的地8271018
心有法竹
白板的微信
相关分类