Saturday, 3 August 2019

Assignment No: 6 Simple Calculator

'''
Assignment No: 6
To simulate simple calculator that performs basic tasks such as,
addition,
subtraction,
multiplication and division.
'''

def add(x, y): # function definition of addition
   return x + y

def subtract(x, y): # function definition of subtraction
   return x - y

def multiply(x, y): # function definition multiplication
   return x * y

def divide(x, y): # function definition of divide
   return x / y

def main():
while(1):
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")

# Take input from the user 
choice = input("Enter choice(1/2/3/4):")
try:
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
except:
print("Enter numbers as integers")
continue

if choice == '1':
  print(num1,"+",num2,"=", add(num1,num2))

elif choice == '2':
  print(num1,"-",num2,"=", subtract(num1,num2))

elif choice == '3':
  print(num1,"*",num2,"=", multiply(num1,num2))

elif choice == '4':
  print(num1,"/",num2,"=", divide(num1,num2))
else:
  print("Invalid input")

if __name__ == '__main__':
main()


60 comments:

  1. Very nice program and easy to understand

    ReplyDelete
  2. It Help us in basic calculations.

    ReplyDelete
  3. I loved this programme because this programme is very easily runs and easy to understand..😊✌️🀩😎

    ReplyDelete
  4. Thanks everyone for ur valuable comments for more update and improvements too

    ReplyDelete
  5. Sir how to make a scientific calculator

    ReplyDelete
  6. Thanks sir to help and support us to make the program easy and run......

    ReplyDelete
  7. It's very informative and easy program

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. But it says at last interval the name is not defined

    ReplyDelete
  10. A good way to learn not only the basic aspects of Python but also compiling various operations under one code.

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. It help us in daily basic calculations .

    ReplyDelete
  13. B 02 Ganesh Gaikwad
    It help us in daily basic calculations

    ReplyDelete
  14. B-13-Ghumare Sonali Sudam
    Easy to help in daily basic calculation

    ReplyDelete
  15. B-19- shrutika holkar
    Easily understand

    ReplyDelete
  16. B-29-pooja kedar
    Easily understood

    ReplyDelete

Microsoft’s latest Surface Pro X is now available in India

  Microsoft Surface Pro X 2020 is now available in India at a starting price of Rs 1,49,999.  Here's everything you would like to unders...