0

I have put together this code. It should assess if inserted value of value_a is in the range between 0 and 10. If yes the code should finish, if not, it should keep asking user to insert number within 0 and 10. But my if statement seems not to be working and it just keep looping that value is not within the range even if I insert correct value. Can anyone please help?

counter = 0
value_a=input("Insert value between 0 and 10:")

while counter == 0: 
   
   if value_a not in range(0,10):
      print(f"{value_a} is not in range between 0 and 10.")
      value_a = input("Insert again value between 0 and 10:")
   else:
        print(f"{value_a} is in range between 0 and 10.")
        counter += 1
  • This is how I fixed the code and it is working: `counter = True value_a = int(input("Insert value between 0 and 10:")) nl = "\n" while counter: if value_a not in range(0,10): print(f"{nl}{value_a} is not in range between 0 and 10.{nl}") value_a = int(input("Insert again value between 0 and 10:")) else: print(f"{nl}{value_a} is in range between 0 and 10.{nl}") counter = False` – JK_coding Aug 03 '21 at 08:23

0 Answers0