SimeonTs

SUPyF2 Functions-Lab - 02. Calculations

Oct 8th, 2019
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. """
  2. Functions - Lab
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1727#1
  4.  
  5. SUPyF2 Functions-Lab - 02. Calculations
  6.  
  7. Problem:
  8. Create a function that receives three parameters and calculates a result depending on operator.
  9. The operator can be  'multiply', 'divide', 'add', 'subtract' .
  10. The input comes as three parameters – two integers and an operator as a string.
  11.  
  12. Example:
  13. Input:      Output:
  14. subtract
  15. 5
  16. 4           1
  17.  
  18. divide
  19. 8
  20. 4           2
  21. """
  22.  
  23.  
  24. def calculator(operator, first_number, second_number):
  25.     if operator == "multiply":
  26.         operator = "*"
  27.     elif operator == "divide":
  28.         operator = "/"
  29.     elif operator == "add":
  30.         operator = "+"
  31.     elif operator == "subtract":
  32.         operator = "-"
  33.     return eval(f"{first_number}{operator}{second_number}")
  34.  
  35.  
  36. print(int(calculator(input(), input(), input())))
Add Comment
Please, Sign In to add comment