Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 29, 2024. It is now read-only.

Commit a3d8f29

Browse files
Add files via upload
1 parent afd3870 commit a3d8f29

File tree

3 files changed

+143
-0
lines changed

3 files changed

+143
-0
lines changed

‎number_guessing‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#NUmber guessing game
2+
"""
3+
Below is a Python implementation of a Number Guessing Game
4+
where the computer generates a random number,
5+
and the player tries to guess it within a certain number of attempts.
6+
we can import random nubers as our wish. Here I take the numbers
7+
betwenn 1 to 50 , we can import as we wish.
8+
"""
9+
import random
10+
11+
def play_guessing_game():
12+
# Generate a random number between 1 and 50
13+
secret_number = random.randint(1, 50)
14+
max_attempts = 10
15+
attempts = 0
16+
17+
print("Welcome to the Number Guessing Game!")
18+
print(f"I'm thinking of a number between 1 and 100. Can you guess it?")
19+
20+
while attempts < max_attempts:
21+
try:
22+
guess = int(input("Enter your guess: "))
23+
attempts += 1
24+
25+
if guess == secret_number:
26+
print(f"Congratulations! You guessed it right in {attempts} attempts.")
27+
break
28+
elif guess < secret_number:
29+
print("Try a higher number.")
30+
else:
31+
print("Try a lower number.")
32+
33+
except ValueError:
34+
print("Invalid input. Please enter a valid integer.")
35+
36+
if attempts == max_attempts:
37+
print(f"Sorry, you've reached the maximum number of attempts. The secret number was {secret_number}.")
38+
39+
if __name__ == "__main__":
40+
play_guessing_game()

‎simple_calculator‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
def add(x, y):
2+
"""Function to add two numbers"""
3+
return x + y
4+
5+
def subtract(x, y):
6+
"""Function to subtract two numbers"""
7+
return x - y
8+
9+
def multiply(x, y):
10+
"""Function to multiply two numbers"""
11+
return x * y
12+
13+
def divide(x, y):
14+
"""Function to divide two numbers"""
15+
if y != 0:
16+
return x / y
17+
else:
18+
return "Error: Cannot divide by zero"
19+
20+
def main():
21+
print("Simple Calculator")
22+
print("Available operations:")
23+
print("1. Add")
24+
print("2. Subtract")
25+
print("3. Multiply")
26+
print("4. Divide")
27+
28+
choice = input("Enter your choice (1/2/3/4): ")
29+
30+
num1 = float(input("Enter the first number: "))
31+
num2 = float(input("Enter the second number: "))
32+
33+
if choice == '1':
34+
print(f"Result: {num1} + {num2} = {add(num1, num2)}")
35+
elif choice == '2':
36+
print(f"Result: {num1} - {num2} = {subtract(num1, num2)}")
37+
elif choice == '3':
38+
print(f"Result: {num1} * {num2} = {multiply(num1, num2)}")
39+
elif choice == '4':
40+
print(f"Result: {num1} / {num2} = {divide(num1, num2)}")
41+
else:
42+
print("Invalid choice. Please select a valid operation (1/2/3/4).")
43+
44+
if __name__ == "__main__":
45+
main()

‎to_dolist‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
class ToDoList:
2+
def __init__(self):
3+
self.tasks = []
4+
5+
def add_task(self, task):
6+
self.tasks.append(task)
7+
print(f"Task '{task}' added successfully!")
8+
9+
def delete_task(self, task):
10+
if task in self.tasks:
11+
self.tasks.remove(task)
12+
print(f"Task '{task}' deleted successfully!")
13+
else:
14+
print(f"Task '{task}' not found.")
15+
16+
def mark_completed(self, task):
17+
if task in self.tasks:
18+
print(f"Task '{task}' marked as completed!")
19+
else:
20+
print(f"Task '{task}' not found.")
21+
22+
def display_tasks(self):
23+
print("\nCurrent tasks:")
24+
for i, task in enumerate(self.tasks, start=1):
25+
print(f"{i}. {task}")
26+
27+
def main():
28+
todo = ToDoList()
29+
30+
while True:
31+
print("\nMenu:")
32+
print("1. Add Task")
33+
print("2. Delete Task")
34+
print("3. Mark Task as Completed")
35+
print("4. Display Tasks")
36+
print("5. Exit")
37+
38+
choice = input("Enter your choice (1/2/3/4/5): ")
39+
40+
if choice == '1':
41+
task = input("Enter the task: ")
42+
todo.add_task(task)
43+
elif choice == '2':
44+
task = input("Enter the task to delete: ")
45+
todo.delete_task(task)
46+
elif choice == '3':
47+
task = input("Enter the task to mark as completed: ")
48+
todo.mark_completed(task)
49+
elif choice == '4':
50+
todo.display_tasks()
51+
elif choice == '5':
52+
print("Exiting the application. Have a great day!")
53+
break
54+
else:
55+
print("Invalid choice. Please select a valid option.")
56+
57+
if __name__ == "__main__":
58+
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /