Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Armstrong_number → ARMSTRONG_NUMBER.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ def is_armstrong_number(number):
numberstr = str(number)
length = len(numberstr)
num = number
rev = 0
temp = 0
while num != 0:
rem = num % 10
Expand Down
70 changes: 70 additions & 0 deletions NUMBER_GUESSING_GAME.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
Module Name: Number Guessing Game
Description: A simple interactive game where the user sets an upper bound,
the program picks a random secret number within that range,
and the user guesses repeatedly until correct. Reports total
guesses taken at the end.
Author: Gaurav Sharma
Date: 2026-08-18
"""

import random


def get_upper_bound() -> int:
"""Prompt the user for a valid upper bound.

Returns:
An integer upper bound of 2 or greater.
"""
while True:
raw = input("Enter the upper bound for the range (e.g. 100): ")
if raw.isdigit() and int(raw) >= 2:
return int(raw)
print("Please enter an integer of 2 or greater.")


def get_guess(upper_bound: int) -> int:
"""Prompt the user for a valid guess within the given range.

Args:
upper_bound: The maximum valid value for a guess.

Returns:
An integer guess between 1 and upper_bound, inclusive.
"""
while True:
raw = input(f"Your guess (1-{upper_bound}): ")
if raw.isdigit() and 1 <= int(raw) <= upper_bound:
return int(raw)
print(f"Enter a whole number between 1 and {upper_bound}.")


def play_game() -> None:
"""Run a single round of the number guessing game.

Selects a secret number, collects guesses until the correct value
is entered, and reports the total number of guesses taken.
"""
upper_bound = get_upper_bound()
secret_number = random.randint(1, upper_bound)
guesses = 0

print(f"\nI'm thinking of a number between 1 and {upper_bound}.")

while True:
guess = get_guess(upper_bound)
guesses += 1

if guess < secret_number:
print("Too Low")
elif guess > secret_number:
print("Too High")
else:
print(f"\nCorrect! The number was {secret_number}.")
print(f"Total guesses: {guesses}")
return


if __name__ == "__main__":
play_game()
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Feel free to explore the scripts and use them for your learning and automation n
41. [Extract Thumbnail From Video](https://github.com/geekcomputers/Python/tree/ExtractThumbnailFromVideo) - Extract Thumbnail from video files
42. [How to begin the journey of open source (first contribution)](https://www.youtube.com/watch?v=v2X51AVgl3o) - First Contribution of open source
43. [smart_file_organizer.py](https://github.com/sangampaudel530/Python2.0/blob/main/smart_file_organizer.py) - Organizes files in a directory into categorized subfolders based on file type (Images, Documents, Videos, Audios, Archives, Scripts, Others). You can run it once or automatically at set intervals using the `--path` and `--interval` options.
44. [number_guessing.py](https://github.com/geekcomputers/Python/blob/master/number_guessing.py) - Interactive number guessing game where the user sets an upper bound and guesses a randomly generated number until correct.
<hr>

_**Note**: The content in this repository belongs to the respective authors and creators. I'm just providing a formatted README.md for better presentation.