Created
June 25, 2025 09:20
-
-
Save shinysu/6323b4783009857de7cf2da8ac85ead1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
number = 7 | |
print("Welcome to the Guessing Game!") | |
guess = int(input("Guess a number between 1 and 10: ")) | |
if guess == number: | |
print("Yay! You guessed it right!") | |
else: | |
print("Oops! Wrong guess") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
computer_choice = random.randint(1, 10) | |
print("Welcome to the Guessing Game!") | |
user_guess = int(input("Guess a number between 1 and 10: ")) | |
if user_guess == computer_choice: | |
print("Yay! You guessed it right!") | |
else: | |
print("Oops! Wrong guess") | |
print(f"The correct number was: {computer_choice}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
computer_choice = random.randint(1, 10) | |
def play_game(user_guess, computer_choice): | |
print(f"\nYou guessed: {user_guess}") | |
print(f"Computer chose: {computer_choice}") | |
if user_guess == computer_choice: | |
return "Yay! You guessed it right!" | |
else: | |
return "Oops! Wrong guess" | |
print("Welcome to the Guessing Game!") | |
user_guess = int(input("Guess a number between 1 and 10: ")) | |
play_game(user_guess, computer_choice) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
computer_choice = random.randint(1, 10) | |
def play_game(user_guess, computer_choice): | |
print(f"\nYou guessed: {user_guess}") | |
print(f"Computer chose: {computer_choice}") | |
if user_guess < computer_choice: | |
print("Too low! Try again.") | |
elif user_guess > computer_choice: | |
print("Too high! Try again.") | |
else: | |
print("Yay! You guessed it right!") | |
print("Welcome to the Guessing Game!") | |
while True: | |
user_guess = int(input("Guess a number between 1 and 10: ")) | |
if user_guess < 1 or user_guess > 10: | |
print("Please guess a number between 1 and 10.") | |
continue | |
play_game(user_guess, computer_choice) | |
play_again = input("Do you want to play again? (yes/no): ").strip().lower() | |
if play_again != 'yes': | |
print("Thanks for playing! Goodbye!") | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment