Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import ceil, floor
- def kys(l):
- s_n = l[1:-1].split(', ')
- if '/' in s_n[0]:
- s_n[0] = calculate(s_n[0])
- else:
- s_n[0] = int(s_n[0])
- if '/' in s_n[1]:
- s_n[1] = calculate(s_n[1])
- else:
- s_n[1] = int(s_n[1])
- return s_n
- def calculate(s_val):
- s_splitted = s_val.split('/')
- return int(s_splitted[0])/int(s_splitted[1])
- s = input()
- fb = s[0]
- lb = s[-1]
- if fb == '[' and lb == ']':
- s_new = kys(s)
- print(floor(s_new[1]) - ceil(s_new[0]) + 1)
- elif fb == '(' and lb == ')':
- s_new = kys(s)
- if round(s_new[0]) == s_new[0] or round(s_new[1]) == s_new[1]:
- print(ceil(s_new[1] - s_new[0]) - 1)
- else:
- print(floor(s_new[1] - s_new[0]))
- else:
- s_new = kys(s)
- if (round(s_new[0]) == s_new[0] and fb == '[') or (round(s_new[1]) == s_new[1] and lb == ']'):
- print(ceil(s_new[1] - s_new[0]))
- else:
- print(floor(s_new[1] - s_new[0]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement