我有一些代碼我亂搞..非常新的python和編碼一般,但是我難住這一個。蜇傷回來名稱錯誤
我定義了一個函數,並從中獲得了一些用戶輸入。當我嘗試打印輸入時,出現NameError:name'my_name'未定義。
這裏是代碼..
#New Program
#Written by Chris Nelson of Cnelson Creations
#This code obtains some basic information from the user
def questions():
if userinput == "Y":
my_name = input("What is your name? ")`enter code here`
my_age = input("What is your age? ")
my_urname = input("Please pick a username.. ")
my_psword = input("Please pick a password.. ")
elif userinput == "N":
print ("Sorry we need the information to continue..")
print ("... Goodbye")
exit()
else:
print ("Not a valid choice.. Goodbye!")
exit()
print ("We need to obtain some information from you before going forward")
print ("Is this ok? Enter Y for 'yes' or N for 'No'...")
userinput = input("Please enter Y or N ")
questions() #This code runs the function listed above..
print ("Great we have some information from you!")
print ("Lets confirm it is the correct information.. ")
print ('{}, {}, {}, {}, is this information correct?'.format(my_name, my_age, my_urname, my_psword))
你有** **範圍問題。 – keyser 2014-12-27 16:22:13
如果可以,你能否詳細說明一下?謝謝,克里斯。 – 2014-12-27 16:23:32