day #6 - Exercise 1: make two Calculator using in python
I have two calculator programs code :
You can easily use it on computer and mobile:-
Our 1st.Question--
Create a calculator capable of performing addition , subtraction, multiplication and division operations
on two numbers.
Our program code--
Input-
a=int(input("enter your first number:"))
b=int(input("enter your second number:"))
print(a+b)
print(a-b)
print(a*b)
print(a/b)
Output-
enter your first number:5
enter your second number:5
10
0
25
1.0
Our 2nd Question.:
how to make best & advance calculator to include anything.?
Our program code:
def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
if y == 0:
return "Error! Division by zero!"
else:
return x / y
print("Select operation:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")
while True:
choice = input("Enter choice (1/2/3/4): ")
if choice in ('1', '2', '3', '4'):
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if choice == '1':
print("Result:", add(num1, num2))
elif choice == '2':
print("Result:", subtract(num1, num2))
elif choice == '3':
print("Result:", multiply(num1, num2))
elif choice == '4':
print("Result:", divide(num1, num2))
else:
print("Invalid Input")
next_calculation = input("Do you want to perform another calculation? (yes/no): ")
if next_calculation.lower() != 'yes':
break
Output-
Great my brother please keep it up
ReplyDeleteThanks Swastik bhai...
ReplyDeleteWhen will next class come
ReplyDeleteMake the date 17th May in your mind as my birthday
ReplyDeleteWish you a very happy birthday my bro...
DeleteKeep hard work and Grow
Thanks Anubhav bro
ReplyDeleteI am waiting long away for your message
ReplyDeleteWas Busy some work bro
Delete