Цель этой игры - угадать число в трех попытках, и если вы это исправите, поздравите вас, и если вы ошибетесь, скажите «Нет». Я думаю, что у меня есть код правильно, но я новичок в программировании и не уверен. Я тестирую его, если он работает, но это может занять ОЧЕНЬ долгое время. Любая помощь приветствуется!Что касается Python Guessing Game
# Guess My Number
#
# The computer picks a random number between 1 and 100
# The player tries to guess it and the computer lets
# the player know if the guess is too high, too low
# or right on the money
import random
print("\tWelcome to 'Guess My Number'!")
print("\nI'm thinking of a number between 1 and 100.")
print("Try to guess it in as few attempts as possible.\n")
# set the initial values
the_number = random.randint(1, 100)
guess = int(input("Take a guess: "))
tries = 1
# guessing loop
while guess != the_number:
if guess > the_number:
print("Lower...")
elif tries == 3:
break
else:
print("Higher...")
guess = int(input("Take a guess: "))
tries += 1
if guess == the_number:
print("You guessed it! The number was", the_number)
print("And it only took you", tries, "tries!\n")
input("\n\nPress the enter key to exit.")
if tries == 3:
print("no")
input("\n\nPress the enter key to exit.")
Вы должны запустить его и посмотреть. Если потребуется некоторое время, вы узнаете, как обнаружить, исправить и, надеюсь, предотвратить ошибки в будущем. – cwallenpoole