Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- #
- # https://www.facebook.com/groups/learnpython.org/permalink/1173109739420308/
- #
- # its a claculater program
- # in the begning we are creating our own function using defr operator
- def menu():
- # print what we want to print
- print("welcome to claculator")
- print("your options are:")
- print()
- print("1. addition")
- print("2. subtraction")
- print("3. multiplication")
- print("4. division")
- print("5. quit clac")
- print()
- return input("choose your option: ")
- # now def fn for add two nos and same for all
- def add(a, b):
- print(a, "+", b, "=", a+b)
- def sub(a, b):
- print(a, "-", b, "=", a-b)
- def mul(a, b):
- print(a, "*", b, "=", a*b)
- def div(a, b):
- print(a, "/", b, "=", a/b)
- # now code really starts from here after defining
- while True:
- choice = menu()
- # choice is a text so compare with text "1", "2", etc.
- if choice == "1":
- x = int(input("add this: "))
- y = int(input("to this : "))
- add(x, y)
- elif choice == "2":
- x = int(input("subtract this: "))
- y = int(input("from this : "))
- sub(x, y)
- elif choice == "3":
- x = int(input("multiply this: "))
- y = int(input("by this : "))
- mul(x, y)
- elif choice == "4":
- x = int(input("divide this: "))
- y = int(input("by this : "))
- div(x, y)
- elif choice == "5":
- break # leaving `while True` loop
- print("thank you for using pyclac!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement