You are on page 1of 3

task3

March 25, 2024

[ ]: import numpy as np

[ ]: def lucky_draw_hard():
while True:
# Increase the number of tickets
tickets = np.arange(1, 22)

# Randomly select the winning ticket


winning_ticket = np.random.choice(tickets)

# Limit the number of guesses


max_guesses = 3
guesses_remaining = max_guesses

# Initialize score
score = 0

# Welcome message
print("Welcome to the Hard Lucky Draw Game!")
print(f"Guess the winning ticket number (between 1 and 20) in␣
↪{max_guesses} attempts.")

# Loop for guessing


while guesses_remaining > 0:
# User input for their guess
user_guess = input(f"Guess {max_guesses - guesses_remaining + 1}: ")

# Check if the user's input is None or empty


if user_guess is None or user_guess.strip() == "":
print("Please enter a valid guess.")
continue

# Check if the user's guess is a valid integer


try:
user_guess_int = int(user_guess)
except ValueError:
print("Please enter a valid integer.")

1
continue

# Check if the user's guess matches the winning ticket


if user_guess_int == winning_ticket:
print("Congratulations! You've won the lucky draw!")
score += 1
break
elif user_guess_int != winning_ticket:
print("Sorry, that's not the winning ticket number.")
guesses_remaining -= 1

# If no correct guess within the allowed attempts


if guesses_remaining == 0:
print(f"Sorry, you've used all your attempts. The winning ticket␣
↪number was {winning_ticket}.")

# Display final score


print(f"Your final score: {score}/{max_guesses}")
cont = input("Do you want to play again? Y/n").lower()
if cont == "n":
break

[ ]: lucky_draw_hard()

Welcome to the Hard Lucky Draw Game!


Guess the winning ticket number (between 1 and 20) in 3 attempts.
Guess 1:
Please enter a valid guess.
Guess 1: 9
Sorry, that's not the winning ticket number.
Guess 2: 6
Sorry, that's not the winning ticket number.
Guess 3: 18
Congratulations! You've won the lucky draw!
Your final score: 1/3
Do you want to play again? Y/nY
Welcome to the Hard Lucky Draw Game!
Guess the winning ticket number (between 1 and 20) in 3 attempts.
Guess 1: 4
Sorry, that's not the winning ticket number.
Guess 2: 8
Sorry, that's not the winning ticket number.
Guess 3: 13
Sorry, that's not the winning ticket number.
Sorry, you've used all your attempts. The winning ticket number was 17.
Your final score: 0/3
Do you want to play again? Y/nn

2
[ ]:

You might also like