【发布时间】:2017-10-15 04:02:07
【问题描述】:
我已经尝试搜索和尝试人们为他人提出的建议,但它对我不起作用,这是我的代码:
def CreateAccount():
FirstName = input('What is your first name?: ')
SecondName = input('What is your second name?: ')
Age = input('How old are you?: ')
AreaLive = input("What area do you live in?: ")
return FirstName, SecondName, Age, AreaLive
def DisplayAccountInfo(FirstName,SecondName,Age,AreaLive):
print("Your Firstname is",FirstName)
print("Your Secondname is",SecondName)
print("You are",Age," years old")
print("You live in the",AreaLive," area")
return
def ConfirmAccountF():
ConfirmAccount = input("Do you have an account? y,n; ")
if ConfirmAccount == "n":
CreateAccount()
else: #ConfirmAccount -- 'y'
DisplayAccountInfo()
while True:
ConfirmAccountF()
所以它现在应该无限期地运行,但我想要它做的是将变量从“CreateAccount”传递到“DisplayAccountInfo”。
当我为 'ConfirmAccount' 按 n 以外的任何内容时,我发现变量未定义。
如果我在 'DisplayAccountInfo()' 中手动设置它,它不会引发任何错误。
这只是我在搞砸并试图理解 python,如果有人可以提供帮助,那就太好了。
【问题讨论】:
-
createAccount正在返回变量,但您没有将它们分配给任何东西。改为执行data = CreateAccount()之类的操作,然后在DisplayAccountInfo()函数中传递*data -
您想在
DisplayAccountInfo()中显示哪些帐户信息?如果用户输入y,你怎么知道要显示哪个帐户的信息?