我在做一个练习,将键值输入字典。
每次用户用input输入键值对后询问是否再次输入。在判断是否的时候我希望如果希望继续输入用yes,反之输入no.如果输入不是yes或者no会提醒输入错误,重新输入。
但是我的代码在判断环节如果用户输入错误的时候,会进入无限提示输入错误循环,无法跳出。我看了半天无法发现错误,希望有前辈可以帮忙看一下
sign=True
while sign:
a=input('plz enter your name: ')
b=input('plz enter your favourite mountain: ')
responses[a]= b
repeat=input('anyone else would like to type the inf? (yes/no)')
if repeat=='no':
sign=False
elif repeat=='yes':
sign=True
else:
print('invalid typing,try again')
repeat2=input('anyone else would like to type the inf? (yes/no)')
while repeat2!= 'yes' or 'no':
print('invalid typing,try again')
repeat3=input('anyone else would like to type the inf? (yes/no)')