Skip to content

Instantly share code, notes, and snippets.

@shinysu
Created June 25, 2025 09:20
Show Gist options
  • Save shinysu/6323b4783009857de7cf2da8ac85ead1 to your computer and use it in GitHub Desktop.
Save shinysu/6323b4783009857de7cf2da8ac85ead1 to your computer and use it in GitHub Desktop.
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")
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}")
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)
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