Implementei um loop para que o usuário não selecione uma opção invalida de dificuldade.
import random
print("*******************************")
print("Wellcome to the guessing game!")
print("*******************************")
secret_number = random.randrange(1, 101)
roll = 1
attempts = 0
score = 1000
correct = 0
choice = 1
while choice:
print("Difficult:\n")
difficult = int(input("1 - Easy\n2 - Medium\n3 - Hard\n"))
if difficult == 1:
attempts = 10
choice = 0
elif difficult == 2:
attempts = 5
choice = 0
elif difficult == 3:
attempts = 3
choice = 0
else:
print("Chose a valid difficult.\n")
for roll in range(1, attempts + 1):
print("Attempt {} of {}".format(roll, attempts), end="\n\n")
guess_str = input("Type a number between 1 and 100: ")
print("Your guess is", guess_str, end="\n\n")
guess_int = int(guess_str)
if (guess_int < 1) or (guess_int > 100):
print("You must enter a number between 1 and 100!")
continue
equals = guess_int == secret_number
greater = guess_int > secret_number
smaller = guess_int < secret_number
if equals:
print(f"Congratulations!! The secret number is {secret_number}.\nYour score was {score}")
correct = 1
break
else:
if smaller:
print("Secret number > ", guess_int, end="\n\n")
elif greater:
print(guess_int, " > Secret number.", end="\n\n")
score_loss = abs(secret_number - guess_int)
score -= score_loss
if correct:
print("END")
else:
print("You don't have more tries.")
print(f"The secret number was {secret_number}. Good luck next time!")