Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- command = input()
- num1 = int(input())
- num2 = int(input())
- def calculation():
- if command == "multiply":
- return num1 * num2
- elif command == "divide":
- if num1 != 0:
- return num1 / num2
- elif command == "add":
- return num1 + num2
- elif command == "subtract":
- return num1 - num2
- print(int(calculation()))
- Или с вложени функции:
- command = input()
- num1 = int(input())
- num2 = int(input())
- def calculation():
- def multiply():
- return num1 * num2
- def divide():
- if num1 != 0:
- return num1 / num2
- def add():
- return num1 + num2
- def subtract():
- return num1 - num2
- return {"multiply": multiply(), "divide": divide(), "add": add(), "subtract": subtract()}[command]
- print(int(calculation()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement