我不明白为什么它一直重复这个函数,即使满足了将while循环更改为false的条件。下面是我要做的一个例子:
confirm=True
def program():
name=input("What is your name? ")
country=input("What is your country? ")
runagain=input("Would you like to run again? Enter no or yes: ")
if runagain=="no":
print("Thank You")
confirm=False
else:
print("Rerun")
confirm=True
while confirm==True:
program()
必须在方法程序中使用全局确认。你知道吗
看看这个
使用global是编写代码的错误标志。 相反,您删除了代码中的大量代码,从而减少了行数。 参考此
如果可能的话,应该避免使用global。尽管使用
global
可以解决这个问题,但最好避免使用它。你知道吗如果
program()
成功返回,那会很有帮助。你知道吗例如:
Python是静态范围的
http://python-textbok.readthedocs.io/en/1.0/Variables_and_Scope.html
全局关键字起作用,但可能适得其反。。。你知道吗
相关问题 更多 >
编程相关推荐