2 回答

TA貢獻1871條經驗 獲得超8個贊
您必須讓 show() 在其中包含一個參數。例如:
def show(n):
print(n)
因此,當您調用 show(n) 時,它會將您包含的任何內容打印為 n。
所以如果你打電話給 show(name)。它會打印出名稱。
def show(n):
print(n)
show(name) #This would print out name.
除非您返回一個值,否則您也不需要return。Return 不會使代碼返回,它只會使函數返回一個值。所以你確實需要返回 list() 和 create(),但不需要返回 show(n)。
編輯 您還希望在調用 create 時將用戶輸入設置為變量。
def main():
print("Choose from the following list:")
while True:
choice = lista()
if (choice == 0):
print("Thanks for using the program!")
break
elif (choice == 1):
name = create() #Here is where you should change it
elif (choice == 2):
show(name)
else:
print("Input not detected.\nStopping.")
break
添加回答
舉報