0% found this document useful (0 votes)
3 views2 pages

Number Guessing Game Tournament

Uploaded by

aldohamarine
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Number Guessing Game Tournament

Uploaded by

aldohamarine
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import random

def play_round():
secret_number = [Link](1, 50)
attempts = 0
max_attempts = 6

while attempts < max_attempts:


try:
guess = int(input(f"Attempt {attempts + 1}/6 - Enter your guess (1-50):
"))
except ValueError:
print("Please enter a valid integer.")
continue

if guess < 1 or guess > 50:


print("Guess must be between 1 and 50.")
continue

attempts += 1

if guess < secret_number:


print("Too low.")
elif guess > secret_number:
print("Too high.")
else:
print("Correct!")
break

score = max(0, 10 - attempts)


print(f"Round score: {score}\n")
return score

def play_tournament():
total_score = 0
for round_num in range(1, 4):
print(f"--- Round {round_num} ---")
round_score = play_round()
total_score += round_score
print(f"Tournament score: {total_score}")
return total_score

def main():
best_score = 0

while True:
print("\nStarting a new 3-round tournament!")
tournament_score = play_tournament()

if tournament_score > best_score:


best_score = tournament_score
print("New best score!")

print(f"Best cumulative score so far: {best_score}")

again = input("Do you want to try to beat your score? (yes/no):


").strip().lower()
if again not in ["yes", "y"]:
print("Thanks for playing!")
print(f"Your best tournament score was: {best_score}")
break

if __name__ == "__main__":
main()

You might also like