Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
867
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. actions = ['*', '/', '+', '-']
  2.  
  3. first = str(input('Введите первую дробь: '))
  4. second = str(input('Введите вторую дробь: '))
  5. action = str(input('Выберите операцию (*, /, +, -): '))
  6. while True:
  7.     if action not in actions:
  8.         action = str(input('Выберите корректную операцию (*, /, +, -): '))
  9.     else:
  10.         break
  11.  
  12. a = int(first.split('/')[0])
  13. b = int(first.split('/')[1])
  14. c = int(second.split('/')[0])
  15. d = int(second.split('/')[1])
  16.  
  17. if action == '*':
  18.     print(str(a * c) + '/' + str(b * d))
  19. elif action == '/':
  20.     print(str(a * d) + '/' + str(b * c))
  21. elif action == '+':
  22.     print(str((a * d) + (c * b)) + '/' + str(b * d))
  23. elif action == '-':
  24.     print(str((a * d) - (c * b)) + '/' + str(b * d))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement