Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- actions = ['*', '/', '+', '-']
- first = str(input('Введите первую дробь: '))
- second = str(input('Введите вторую дробь: '))
- action = str(input('Выберите операцию (*, /, +, -): '))
- while True:
- if action not in actions:
- action = str(input('Выберите корректную операцию (*, /, +, -): '))
- else:
- break
- a = int(first.split('/')[0])
- b = int(first.split('/')[1])
- c = int(second.split('/')[0])
- d = int(second.split('/')[1])
- if action == '*':
- print(str(a * c) + '/' + str(b * d))
- elif action == '/':
- print(str(a * d) + '/' + str(b * c))
- elif action == '+':
- print(str((a * d) + (c * b)) + '/' + str(b * d))
- elif action == '-':
- print(str((a * d) - (c * b)) + '/' + str(b * d))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement