我正在學習使用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