Advertisement
OPiMedia

Simple inequalities with 1 variable

Jan 3rd, 2021
1,903
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. """
  5. Get lines like that:
  6. x < 42
  7. x > 0.2
  8. x < 0.4
  9. x > 0.3
  10.  
  11. And print final interval:
  12. 0.3 < x < 0.4
  13. """
  14.  
  15. import sys
  16.  
  17.  
  18. def main() -> None:
  19.     lower = float(-2**32)
  20.     upper = float(2**32)
  21.     for line in sys.stdin:
  22.         line = line.rstrip()
  23.         variable, operator, value_str = line.split()
  24.  
  25.         assert variable == 'x'
  26.  
  27.         value = float(value_str)
  28.         if operator == '<':
  29.             upper = min(upper, value)
  30.         else:
  31.             assert operator == '>'
  32.  
  33.             lower = max(lower, value)
  34.  
  35.     print(f'{lower} < x < {upper}')
  36.  
  37.  
  38. if __name__ == '__main__':
  39.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement