Nov-10-2019, 04:07 PM
I am writing a program using while loop to determine the highest and lowest of a user's inputted numbers, allowing the user to enter as many numbers as they wish, before using the sentinel value of -1 to exit. Then, the program should print the lowest and the highest inputted values. My problem is, the sentinel value keeps entering the loop as an input value and is being considered part of the range. If the user does not enter a number below my sentinel value of -1, then the sentinel value is what appears as the lowest. I've spent time trying to fix it but without success. Does anyone have any ideas as to why this is happening and what should be done to mend it? Here is my code:
minimum = int() highest = int() while(True): num = int(input("Enter a Number (Use -1 to Stop): " )) if highest < num: highest = num if minimum > num: minimum = num if(num == -1): break print("The interval is",minimum,"-", highest)