Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. __operators = ('+', '-', '/', '//', '*', '**', '%')
  3.  
  4.  
  5. def print_error_message():
  6.     print("Калкулаторот треба да ги подржува следните операции:\n"
  7.           "Собирање (+)\n"
  8.           "Одземање (-)\n"
  9.           "Множење (*)"
  10.           "Целобројно делење (//)\n"
  11.           "Делење (/)\n"
  12.           "Модуло (остаток) (%)\n"
  13.           "Степенување (**)")
  14.  
  15.  
  16. def do_evaluation(x, operator, y):
  17.     if operator == '+':
  18.         return x + y
  19.  
  20.     elif operator == '-':
  21.         return x - y
  22.  
  23.     elif operator == '/':
  24.         return x / y
  25.  
  26.     elif operator == '//':
  27.         return x // y
  28.  
  29.     elif operator == '*':
  30.         return x * y
  31.  
  32.     elif operator == '**':
  33.         return x ** y
  34.  
  35.     elif operator == '%':
  36.         return x % y
  37.  
  38.     else:
  39.         return None
  40.  
  41.  
  42. def calculator():
  43.     x = eval(input())
  44.     operator = eval(input())
  45.     y = eval(input())
  46.  
  47.     print(str(x) + operator + str(y))
  48.  
  49.     # your code here
  50.     rezultat = do_evaluation(x, operator, y)
  51.  
  52.     if rezultat is None:
  53.         print_error_message()
  54.     else:
  55.         print(rezultat)
  56.  
  57.     return rezultat
  58.  
  59.  
  60. if __name__ == "__main__":
  61.     calculator()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement