当我询问用户:“Doyouwanttoruntheprogrammearth”时,我希望再次运行一个程序。不去退出,是的循环和运行主要再次。但是我注意到python保存了旧的变量赋值。有没有一种快速的方法来清除内存,以便在程序循环时再次存储新的变量?你知道吗
现在我得到的是:请关闭程序并重新打开它!想让它更优雅:
到目前为止我得到的是:
def main()
print("Do you want to solve another problem?")
answer = input()
while answer not in["yes","no"]:
answer = input()
if answer == "yes":
print("Please close the program and rerun it")
#main() #<-this is not working as expected
else:
exit()
您可以做的一件事是本地化变量并使用clean-up函数来处理启动新会话
区别在于
if answer == 'yes'
将设置answer = None
以清除它相关问题 更多 >
编程相关推荐