为什么会一直循环下去?
{:5_100:} 输入no也无法出循环,求助大佬蟹蟹def again():
answer = ''
while answer != 'yes' and answer != 'no':
answer = input('do you want to have play again?(yes or no):')
answer = 'yes'
while answer == 'yes':
again() 修改局部变量不会影响全局变量。这样试试:
def again():
answer = input('do you want to have play again?(yes or no):')
return answer
answer = 'yes'
while answer == 'yes':
answer = again() def again():
global answer
while answer != 'no':
answer = input('do you want to have play again?(yes or no):')
answer = 'yes'
again() qiuyouzhi 发表于 2020-8-7 18:17
好的蟹蟹大佬{:5_105:} zltzlt 发表于 2020-8-7 18:16
修改局部变量不会影响全局变量。这样试试:
谢谢大佬{:5_105:} zltzlt 发表于 2020-8-7 18:16
修改局部变量不会影响全局变量。这样试试:
大佬这个return answer 是不是可以不用加呀
始不垂翅 发表于 2020-8-8 06:52
大佬这个return answer 是不是可以不用加呀
必须要加,这是函数的返回值
页:
[1]