Technical Skills
“Python: Where elegance meets functionality, and code becomes poetry.
In my journey through the Basic Programming course, I undertook a compelling final project—an interactive “Number Guessing Game.” Guided by foundational programming concepts, I designed a user-friendly interface where players attempt to decipher a randomly generated number within a predefined range. Through this endeavor, I honed my skills in handling user input, employing conditional statements for logic, and integrating loops for iterative gameplay. By implementing error handling techniques, I ensured a seamless user experience. The project encapsulated my growth, underscoring my ability to transform theoretical knowledge into a functional, engaging application.
import random
def guess_number(secret_number, max_attempts):
print("Welcome to the Number Guessing Game!")
print(f"I'm thinking of a number between 1 and {max_attempts}.")
print("Can you guess it?")
attempts = 0
while attempts < max_attempts:
try:
guess = int(input("Enter your guess: "))
except ValueError:
print("Please enter a valid number.")
continue
attempts += 1
if guess < secret_number:
print("Too low! Try again.")
elif guess > secret_number:
print("Too high! Try again.")
else:
print(f"Congratulations! You guessed the number {secret_number} in {attempts} attempts!")
break
else:
print(f"Sorry, you've run out of attempts. The number was {secret_number}.")
if __name__ == "__main__":
max_range = 100
secret_number = random.randint(1, max_range)
max_attempts = 10
guess_number(secret_number, max_attempts)