所以,我正在编写一个代码,询问我的名字,然后问我是否确定这是我的名字。如果我回答“ S”,它会继续,如果我回答“ N”,它会再次问我我的名字,它应该返回到循环的顶部并询问我是否确定,但不是。如果我既不回答“ S”也不回答“ N”,它会再次询问我是否确定。
print('Hi! Whats your name?')
nome = input().title()
while len(nome) < 3 or len(nome) > 10:
print('That name doesnt sound real. Please, tell me your real name.')
nome = input().title()
else:
respostass = ['Sim', 'S']
respostasn = ['Não', 'N', 'Nao']
print('Are you sure your names ' + nome + '?')
certeza = input().title()
while certeza not in respostass and certeza not in respostasn:
print('I did not understood what you meant. Are you sure or not?')
certeza = input().title()
if certeza in respostass:
print("Nice. Let us continue.")
else:
print('So, whats your name?')
nome = input().title()
continue
它给了我这个错误:
File "C:/Users/Hugo/.PyCharmCE2019.1/config/scratches/scratch.py", line 22
continue
^
SyntaxError: 'continue' not properly in loop
答案 0 :(得分:0)
在格式化时,我注意到您遇到了一些字符串问题。请相应地使用" "
和' '
,否则可能会出现更多语法错误。但是,您实际上并不需要continue
语句。我想您要在用户确认后停止播放?
print("Hi! What's your name?")
nome = input().title()
while len(nome) < 3 or len(nome) > 10:
print("That name doesn't sound real. Please, tell me your real name.")
nome = input().title()
else:
respostass = ['Sim', 'S']
respostasn = ['Não', 'N', 'Nao']
print("Are you sure your name's " + nome + '?')
certeza = input().title()
while certeza not in respostass:
if certeza not in respostasn:
print('I did not understood what you meant. Are you sure or not?')
certeza = input().title()
else:
print("So, what's your name?")
nome = input().title()
print("Are you sure your name's " + nome + '?')
certeza = input().title()