1
resposta

Mão na massa: Com numeros randomicos

import random

print(34*"'")
print("|  Welcome to the Guessing Game  | ")
print(34*"'")


# Criando e selecionando o numero secreto de forma randomica usando a lib "random" e a função .randrange()

secret_number = random.randrange(1, 51)

max_turn = 5

print("What is the secret number?")

for turn in range(1, max_turn + 1):
    print(f"Round {turn} of {max_turn} rounds")
    shot_str = input("Choose a number between 1 and 50?")
    shot = int(shot_str)
    if(shot < 1 or shot > 50):
        print("Invalid, you must to choose a number between 1 and 50. Unfurtunately you lost a choice")
        continue
    if(shot == secret_number):
        print("Amazing! You got it right!")
        break
    else:
        if(shot > secret_number and turn < 5):
            print("Too bad, but you were wrong. The secret number is smaller.")
        elif(shot < secret_number and turn < 5):
            print("Too bad, but you were wrong. The secret number is bigger.")
        elif(shot > secret_number or shot < secret_number and max_turn >= 5):
            print(f"Sorry, but you were wrong. The secret number was {secret_number}. The game is over.")
1 resposta

Qual é a dúvida?