Угадай игру, как повторитьPython

Программы на Python
Ответить
Anonymous
 Угадай игру, как повторить

Сообщение Anonymous »

Я работал над этой игрой в угадайку, но не могу заставить ее повторять игру, когда игрок говорит «да».
Игра дает вам 5 попыток угадать номер, о котором он подумал, а затем после того, как он спрашивает вас, хотите ли вы сыграть еще раз, но когда вы говорите «ДА», он просто продолжает повторять предложение, а когда вы говорите «НЕТ», он делает то, что должен, а именно нарушает код.
def main():
game = "your game"
print(game)
play_again()

import random

print("Welcome to the number guessing game!")
counter = 1 # counts attempts it took to guess the number
number = int(random.randint(1, 10))
while counter > 0 and counter number:
print("wrong number! Try again you are too high")
counter = counter + 1
elif guess != number and guess < number:
print("wrong number! Try again you are too low!")
counter = counter + 1
else:
print("Well done! You have guessed the number I was thinking of! The number was ", number)
print("it took you ", counter, "attempts!")
if counter == 2:
print("4 attempts left before program ends")
if counter == 3:
print("3 attempts left before program ends")
if counter == 4:
print("2 attempts left before program ends")
if counter == 5:
print("1 attempts left before program ends")

def play_again():
while True:
play_again = input("Would you like to play again?(yes or no) : ")
if play_again == "yes":
main()
if play_again == "no":
exit()
else:
print("I'm sorry I could not recognize what you entered")

main()


Подробнее здесь: https://stackoverflow.com/questions/400 ... -to-repeat
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»