【发布时间】:2014-07-25 00:27:29
【问题描述】:
def start():
global smallq
global medq
global larq
check = input("Would you like to change prices? Press Y to change or Press N to continue to order: ")
if check == "Y":
password = input("What is the password?: ")
else:
print("Continuing to order...")
smallq = 50
medq = 120
larq = 180
order()
if password == "please":
quilt_price()
else:
print("Wrong password", "\n", "Continuing to order...")
smallq = 50
medq = 120
larq = 180
order()
例外:
Traceback (most recent call last):
File "/Users/palerj09/Documents/SAC RW.py", line 128, in <module>
start()
File "/Users/palerj09/Documents/SAC RW.py", line 18, in start
if password == "please":
UnboundLocalError: local variable 'password' referenced before assignment
如果我写“N”来回答输入它会运行order() 并且一切正常,除非order() 完成它会引发错误。我尝试将password 设为全局,但这似乎不起作用。有什么想法吗?
【问题讨论】:
标签: python python-3.x local