让用户再次输入名称

2024-03-29 09:44:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我想做个游戏。因此,在命名时,我需要帮助,这样一旦玩家说不或其他任何事情,它会要求他们再次输入一个名字。但我似乎找不到办法

input("Disclaimer: To be able to continue through text press Enter")
player_name =  input("What's your name? ")
name = input('Do you want to keep the name' + player_name + '? (No or Yes?)')
if name == 'yes' or 'Yes':
  input('Ok then ' + player_name + ', Enjoy the game!!!')
input('Weclome ' + player_name + ', to planet')
print ('T')
print ('S')
print ('E')
print ('')
print ('0')
print ('6')
input("")
print ('Here we shall learn many things about our know...')
input("")
print ('SYSTEM MALFUNCTION: Core heating, bifunctional cooler has been dammag g g g g')
input("")
print ('Oh no, there seemes to be a problem, let me see if I ca')
print ('SYSTEM ALERT: Ejecting all passengers!!!')
input("")
print ('Oh no, no, no, no, NO, this is not supposed to happen!')
input("")
print ('(A helmet is put onto your head, it fills with fresh oxygen. The bottom area of the passenger seat opens to the colorful Planet of TSE below you)')
input("")
input(player_name + " Are... Are you there?")

Tags: orthetononameyouinputyour
2条回答

把所有的东西放在while True:下,如果他们说不,那么就放continue进入下一个“迭代”

while True:
    answer = input("yes or no?")
    if answer == "yes":
        print("ok")
    if answer == "no":
        continue

把它放进这样一个循环里

name = 'no'
while (name.lower() == 'no'):
  player_name =  input("What's your name? ")
  name = input('Do you want to keep the name' + player_name + '? (No or Yes?)')
input('Weclome ' + player_name + ', to planet')

相关问题 更多 >