0% found this document useful (0 votes)
15 views

Guessing Game - Py

dal roti

Uploaded by

Shivansh Sarkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Guessing Game - Py

dal roti

Uploaded by

Shivansh Sarkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Last login: Sat Jul 22 17:06:11 on console

shivansh@Shivanshs-MacBook-Air ~ % python3
Python 3.11.3 (v3.11.3:f3909b8bc8, Apr 4 2023, 20:12:10) [Clang 13.0.0 (clang-
1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import random
>>>
>>> def generate_random_number():
... return random.randint(1, 100)
...
>>> def get_user_guess():
... try:
... guess = int(input("Enter your guess (between 1 and 100): "))
... return guess
... except ValueError:
... print("Invalid input. Please enter a valid number.")
... return get_user_guess()
...
>>> def play_guessing_game():
... print("Welcome to the Guessing Game!")
... secret_number = generate_random_number()
... attempts = 0
...
>>> while True:
File "<stdin>", line 1
while True:
IndentationError: unexpected indent
>>> guess = get_user_guess()
File "<stdin>", line 1
guess = get_user_guess()
IndentationError: unexpected indent
>>> attempts += 1
File "<stdin>", line 1
attempts += 1
IndentationError: unexpected indent
>>>
>>> if guess < secret_number:
File "<stdin>", line 1
if guess < secret_number:
IndentationError: unexpected indent
>>> print("Too low! Try again.")
File "<stdin>", line 1
print("Too low! Try again.")
IndentationError: unexpected indent
>>> elif guess > secret_number:
File "<stdin>", line 1
elif guess > secret_number:
IndentationError: unexpected indent
>>> print("Too high! Try again.")
File "<stdin>", line 1
print("Too high! Try again.")
IndentationError: unexpected indent
>>> else:
File "<stdin>", line 1
else:
IndentationError: unexpected indent
>>> print(f"Congratulations! You guessed the number {secret_number} in
{attempts} attempts!")
File "<stdin>", line 1
print(f"Congratulations! You guessed the number {secret_number} in {attempts}
attempts!")
IndentationError: unexpected indent
>>> break
File "<stdin>", line 1
break
IndentationError: unexpected indent
>>>
>>> if __name__ == "__main__":
... play_guessing_game()
...
Welcome to the Guessing Game!

You might also like