Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge pull request #1 from salimcodes/salimcodes-patch-1 #38

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
69 changes: 22 additions & 47 deletions Projects/calc.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,22 @@
def calculator():
print("Options:\n\t[1] Add \n\t[2] Subtract \n\t[3] Multiply \n\t[4] Divide \n\t[5] Power \n\t[6] Square root")
ch = int(input("\t--> "))

if ch == 1: #addition
num1 = float(input("1st number --> "))
num2 = float(input("2nd number --> "))
print(f"{num1} + {num2} = {num1 + num2}")
elif ch == 2: #subtraction
num1 = float(input("1st number --> "))
num2 = float(input("2nd number --> "))
print(f"{num1} - {num2} = {num1 - num2}")
elif ch == 3: #multiplication
num1 = float(input("1st number --> "))
num2 = float(input("2nd number --> "))
print(f"{num1} x {num2} = {num1 * num2}")
elif ch == 4: #division
num1 = float(input("Dividend --> "))
num2 = float(input("Divisor --> "))
print(f"{num1} ÷ {num2} = {num1 / num2}")
elif ch == 5: #division
num = float(input("Number --> "))
power = float(input("Power --> "))
print(f"{num} ^ {power} = {num ** power}")
elif ch == 6: #root
num = float(input("Number --> "))
print(f"√{num} = {num**(1/2)}")
else:
print("Invalid input!!")
#====================
# MAIN PROGRAM
print("<-- Basic Calculator -->")
print("Does what it says on the tin!")
print("-" * 30) #decoration

run = 'Y'
while run == 'Y':
calculator()

print("-" * 30)

print("Would you like calculate more?\n\t[Y] Yes\n\t[N] No")
run = input("\t--> ").upper()
while run not in ['Y','YES','N','NO']:
run = input("\t--> ").upper()

print("-" * 30)
ch = int(input("1: Add \n2: Subtract \n3: Multiply \n4: Divide \n5: Square root \nEnter your choice: "))
if ch == 1:
num1 = float(input("Enter number: "))
num2 = float(input("Enter number: "))
print("Addition: " + str(num1 + num2))
elif ch == 2:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
print("Subtraction: " + str(num1 - num2))
elif ch == 3:
num1 = float(input("Enter number: "))
num2 = float(input("Enter number: "))
print("Multiplication: " + str(num1 * num2))
elif ch == 4:
num1 = float(input("Enter number: "))
num2 = float(input("Enter number: "))
print("Division: " + str(num1/num2))
elif ch == 5:
num1 = float(input("Enter number: "))
print("Square root: " + str(num1**(1/2)))
else:
print("Invalid input!!")