My project for course: Introduction to Python Programming; guessing game
przez alexiacenturion2005 @alexiacenturion2005
- 32
- 0
- 0
import random
def generate_number(min_value, max_value):
return random.randint(min_value, max_value)
def play_game():
min_value = 1
max_value = 100
target_number = generate_number(min_value, max_value)
attempts = 0
print("Welcome to the Number Guessing Game!")
print(f"I'm thinking of a number between {min_value} and {max_value}. Can you guess it?")
while True:
guess = int(input("Enter your guess: "))
attempts += 1
if guess < target_number:
print("Too low! Try again.")
elif guess > target_number:
print("Too high! Try again.")
else:
print(f"Congratulations! You've guessed the number {target_number} correctly in {attempts} attempts!")
break
def main():
play_again = 'yes'
while play_again.lower() == 'yes':
play_game()
play_again = input("Do you want to play again? (yes/no): ")
print("Thanks for playing!")
if __name__ == "__main__":
main()

0 komentarzy
Zaloguj się lub dołącz bezpłatnie, aby móc komentować