Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 57

BON SECOURS PUBLIC SCHOOL

GUESS THE NUMBER GAME

-PYTHON

1. W2
SERIAL NO DESCRIPTION

1. W2
7
Solution III
import random

def guess_the_number():

# Generate a random number between 1 and 100


secret_number = random.randint(1, 100) attempts = 0

print("Welcome to Guess the Number Game!") print("I'm


thinking of a number between 1 and 100.")

while True: try:


# Ask the player to guess the number guess =
int(input("Enter your guess: ")) attempts += 1

# Check if the guess is correct if


guess == secret_number:
print(f"Congratulations! You guessed the number {secret_number} in {attempts} attempts.") break
elif guess < secret_number: print("Try
guessing higher.")

else:

print("Try guessing lower.")

except ValueError:

print("Please enter a valid number.")

if name == "main”
guess_the_number()
1. Python Documentation: (https://docs.python.org/3/)
- This official Python documentation was used for understanding the Python programming language, its built-in
functions, and standard libraries.

2. Stack Overflow: (https://stackoverflow.com/)


- The Stack Overflow community provided valuable answers and insights into specific coding challenges I
encountered during the project.

3. "Automate the Boring Stuff with Python" by Al Sweigart


- This book helped me learn Python basics and provided some ideas for implementing the project.

4. GitHub: (https://github.com/)
- GitHub was used for version control and to access open-source repositories for reference and inspiration.

5. Python random module documentation: (https://docs.python.org/3/library/random.html)


- The random module documentation helped me understand how to generate random numbers, a crucial part of the
game.

6. Online tutorials and forums:


- Various online tutorials, blog posts, and forum discussions were consulted for tips and tricks related to Python
game development.

7. "Invent Your Own Computer Games with Python" by Al Sweigart


- This book provided guidance and code examples for creating simple games in Python.

8. YouTube tutorials:
- Several YouTube tutorials on Python game development and random number generation were referenced for
learning and troubleshooting.

9. "Learn Python the Hard Way" by Zed A. Shaw


- This book helped me deepen my understanding of Python programming concepts.

10. Personal experience and experimentation:


- Much of the project's learning and problem-solving came from hands-on experience and experimentation.

You might also like