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
90 changes: 50 additions & 40 deletions 1-Number_Guessing_Game.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,55 @@
import random


def number_guessing_game():
print("Welcome to the Number Guessing Game!")
print("I'm thinking of a number between 1 and 10...")

# Generate a random number between 1 and 10
secret_number = random.randint(1, 10)

# Maximum number of attempts
max_attempts = 3
attempts = 0

# Start the game loop
while attempts < max_attempts:
try:
# Get user's guess
guess = int(input(" Enter your guess: "))

# Check if the guess is correct
if guess == secret_number:
print(f"Congratulations! You guessed the number {secret_number} correctly!")
break
else:
print("Sorry, Try again.")

# Increase the number of attempts
attempts += 1

except ValueError:
print("Invalid input! Please enter a valid number.")

# If max attempts reached and no correct guess
if attempts == max_attempts and guess != secret_number:
print(f"Game over! The correct number was {secret_number}.")

# Ask to play again
play_again = input("\n Do you want to play again? (yes/no): ").lower()
if play_again == "yes":
number_guessing_game()
else:
print("Thanks for playing! Goodbye.")

# Run the game

while True:
print("\nI'm thinking of a number between 1 and 10...")

secret_number = random.randint(1, 10)
max_attempts = 3
attempts = 0

while attempts < max_attempts:
try:
remaining_attempts = max_attempts - attempts
print(f"Attempts remaining: {remaining_attempts}")

guess = int(input("Enter your guess: "))

if guess < 1 or guess > 10:
print("Please enter a number between 1 and 10.")
continue

if guess == secret_number:
print(
f"Congratulations! You guessed the number "
f"{secret_number} correctly!"
)
break

elif guess < secret_number:
print("Too low! Try again.")

else:
print("Too high! Try again.")

attempts += 1

except ValueError:
print("Invalid input! Please enter a valid number.")

if attempts == max_attempts and guess != secret_number:
print(f"Game over! The correct number was {secret_number}.")

play_again = input(
"\nDo you want to play again? (yes/no): "
).lower()

if play_again != "yes":
print("Thanks for playing! Goodbye.")
break


number_guessing_game()
19 changes: 12 additions & 7 deletions 2-To-do-List.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@
elif choice == "3":
if not tasks:
print("No tasks to delete!")
else:
task_number = int(input("🗑️ Enter task number to delete: "))
if 1 <= task_number <= len(tasks):
deleted_task = tasks.pop(task_number - 1)
print(f"Task deleted: {deleted_task}")
else:
print("Invalid task number!")
else:
try:
task_number= int(input("🗑️ Enter task number to delete:"))

if 1 <= task_number <=len(tasks):
deleted_task= tasks.pop(task_number - 1)
print(f"Task deleted: {deleted_task}")
else:
print("Invalid task number!")

except ValueError:
print("Invalid input! Please enter a task number.")

elif choice == "4":
print("Exiting... Goodbye!")
Expand Down