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

Create Calculator.py #104

Open
wants to merge 1 commit into
base: master
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
51 changes: 51 additions & 0 deletions pycalci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
def add(num1, num2):
return num1 + num2

def subtract(num1, num2):
return num1 - num2

def multiply(num1, num2):
return num1 * num2

def divide(num1, num2):
return num1 / num2

loop=1
while loop==1:
print("Please select operation -\n" \
"1. Add\n"\
"2. Subtract\n" \
"3. Multiply\n" \
"4. Divide\n" \
"5. Exit")

try:
select = int(input("--> "))
if(select==5):
loop=0
elif(select>5) :
print("HEYYY,read the damn instructions!\n Do you want to try again?")
else:
number1 = int(input("Enter first number: "))
number2 = int(input("Enter second number:"))

#after selection
if (select == 1):
print(number1, "+", number2, "=",add(number1, number2))

elif (select == 2):
print(number1, "-", number2, "=",subtract(number1, number2))

elif (select == 3):
print(number1, "*", number2, "=",multiply(number1, number2))

elif (select == 4):

if (number2 == 0):
print("[Sorry, the scientist are still figuring out that one]\n")
else:
print(number1, "/", number2, "=",divide(number1, number2))


except:
print("[error, this is IMPOSSIBLE!\n Do you want to try again?]\n")