Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.

simple python game - source code

Last updated on 7 months ago
C
caaSuper Admin
Posted 7 months ago
import random
def guess_number():
 # Generate a random number between 1 and 100
 secret_number = random.randint(1, 100)
 # Initialize the number of attempts
 attempts = 0
 print("Welcome to the Guessing Game!")
 print("I have selected a number between 1 and 100. Can you guess it?")
 while True:
 # Get user input
 guess = int(input("Enter your guess: "))
 # Increment the number of attempts
 attempts += 1
 # Check if the guess is correct
 if guess == secret_number:
 print(f"Congratulations! You guessed the number in {attempts} attempts!")
 break
 elif guess < secret_number:
 print("Too low! Try again.")
 else:
 print("Too high! Try again.")
if __name__ == "__main__":
 guess_number()
You can view all discussion threads in this forum.
You cannot start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You cannot download attachments in this forum.
Sign In
Not a member yet? Click here to register.
Forgot Password?
Users Online Now
Guests Online 2
Members Online 0

Total Members: 11
Newest Member: Jhilam