我正在学习使用Python编写代码。 我创建将进行单位转换程序,但我一直坚持这个错误了好一会儿:在python脚本中处理变量作用域
NameError: name 'ini' is not defined
下面是代码:
a = ("Distance")
b = ("Time")
c = ("Volume")
d = ("Temp")
e = ("Weight")
def conversion_type(first):
if first == ("Distance"):
ini = input("How great a distance am I converting?\n")
elif first == ("Time"):
ini = input("How much time am I converting?\n")
elif first == ("Volume"):
ini = input("How great a volume am I converting?\n")
elif first == ("Temp"):
ini = input("How many degrees am I converting?\n")
elif first == ("Weight"):
ini = input("How much weight am I converting?\n")
else:
print("That not was an afformentioned dimension you dolt.")
def variable_type_converter(ini):
ini = float(ini)
print ("\n Welcome to the Convert-O-Matic\n==============================\n")
print ("I support the following dimensions:\n")
print ("%s, %s, %s, %s, and %s," % (a,b,c,d,e))
first = input("What kind of conversion would you like to do?\n")
conversion_type(first)
variable_type_converter(ini)
print("==========================================")
呃哦!,代码截图让我难过。 –
我很抱歉,插入代码功能正在吐出垃圾 –
@John,再试一次。我们可以随时修改格式,特别是如果您将截图留在那里进行验证(并且验证代码后我们最终会删除截图)。 – paxdiablo