OPiMedia

Simple inequalities with 1 variable

Jan 3rd, 2021
1,477
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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()
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×