我需要帮助在pyhton重新开始一个游戏

2024-09-28 18:57:08 发布

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

我只是不知道如何做一个循环,谢谢你的帮助。你知道吗

from random import randint
print ('Bem vindo!')
random = randint(1, 100)
escolha = 0
reiniciar = 0

while escolha!= random:
     escolha = int(input ('Escolha entre 1 e 100: '))

     if escolha == random:
          print ('Venceste!')
     else:
          if escolha > random:
             print ('Alto')
          else:
             print ('Baixo')
print ('Fim do jogo!')

Tags: fromimportinputifrandomelseintprint
2条回答

欢迎使用StackOverflow。你知道吗

所以你想为你的游戏创建一个CLI,对吗?尝试使用while和input函数,并始终尝试以用户的身份进行思考。有时他并不像我们期望的那样。你知道吗

from random import randint

print ('Bem vindo!')

jogar = 'a'

while jogar not in 'nN':
    random = randint(1, 100)
    escolha = 0
    reiniciar = 0


    while escolha!= random:

        escolha = int(input ('Escolha entre 1 e 100: '))

        if escolha == random:
            print ('Venceste!')
        elif escolha > random:
            print ('Alto')
        else:
            print ('Baixo')

    jogar = input('Deseja jogar um novo jogo? (y/n)\n')
    while jogar not in 'nNyY':
        jogar = input('Escolha uma opção válida (y/n)\n')

print ('Fim do jogo!')

巴西索达岛!!!!你知道吗

我不懂语言,但我认为你需要改变你的逻辑能力:


print ('Bem vindo!')

random = randint(1, 100)

escolha = 0

reiniciar = 0

while escolha!= random:

    escolha = int(input ('Escolha entre 1 e 100: '))

    if escolha == random:

        print ('Venceste!')

    elif escolha > random:
        print ('Alto')
    else:
        print ('Baixo')
print ('Fim do jogo!')```

相关问题 更多 >