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
32 changes: 32 additions & 0 deletions my-awesome-project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
\# Smart Calculator



\## Description

A command-line calculator that performs basic arithmetic operations.



\## Features

\- Add, Subtract, Multiply, Divide

\- Input validation

\- Prevents division by zero



\## Usage

Run:

python app.py



\## Technologies

\- Python

41 changes: 41 additions & 0 deletions my-awesome-project/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
def calculator():
print("=== Smart Calculator ===")

while True:
print("\nChoose operation:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")
print("5. Exit")

choice = input("Enter choice (1-5): ")

if choice == '5':
print("Exiting calculator...")
break

if choice not in ['1','2','3','4']:
print("Invalid choice, try again!")
continue

try:
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
except:
print("Invalid input! Enter numbers only.")
continue

if choice == '1':
print("Result:", a + b)
elif choice == '2':
print("Result:", a - b)
elif choice == '3':
print("Result:", a * b)
elif choice == '4':
if b == 0:
print("Error: Division by zero!")
else:
print("Result:", a / b)

calculator()
Loading