0

I have three inputs x, y and z. How do I set limits for these inputs? Also if I want x to be always greater than y, but less than z how can I do this?

while True:
    try: 

        x, y, z = (float(i) for i in input("Please input the x(meters), y (meters), z, respectively seperated with space:").split())                     
    except ValueError:
        print("Enter values without commas!") 

    if x > 0:
        print("X must be < 0")
    if x < y or x > z:
        print("x must be greater than y but less than z!")
    else:
        break

This code does not work correctly!

AHMED KRS
  • 3
  • 2

1 Answers1

0

Your code seems right. You just need to add continue

Code


while True:
    try:
        x, y, z = (float(i) for i in input("Please input the x(meters), y (meters), z, respectively seperated with space:").split())  
    except ValueError:
        print("Enter values without commas!") 
    if x > 0:
        print("X must be < 0")
        continue
    if x < y or x > z:
        print("x must be greater than y but less than z!")
        continue
    else:
        break
Gary
  • 909
  • 8
  • 20