Python Forum
How to Stop Sentinel Value from Entering Final Output
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Stop Sentinel Value from Entering Final Output
#1
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)
Reply


Messages In This Thread
How to Stop Sentinel Value from Entering Final Output - by ZQ12 - Nov-10-2019, 04:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Eliminate entering QR - Whatsapp web automated by selenium akanowhere 1 3,018 Jan-21-2024, 01:12 PM
Last Post: owalahtole
  problem in entering address of a file in input akbarza 0 619 Oct-18-2023, 08:16 AM
Last Post: akbarza
  syntaxerror when entering a constructor MaartenRo 2 1,941 Aug-03-2020, 02:09 PM
Last Post: MaartenRo
  How do I stop this fast factorization program from printing beyond the 3rd output? Pleiades 6 3,780 Dec-07-2019, 08:43 PM
Last Post: Pleiades
  Blending calculator from final product xerxes106 0 1,589 Dec-05-2019, 10:32 AM
Last Post: xerxes106
  Error when entering letter/character instead of number/integer helplessnoobb 2 6,983 Jun-22-2019, 07:15 AM
Last Post: ThomasL
  Program not entering if statement on false. Scottx125 4 2,898 Nov-12-2018, 06:30 PM
Last Post: Scottx125
  Entering an expression with "input" command johnmnz 3 3,447 Sep-01-2017, 05:20 PM
Last Post: metulburr
  Trouble when entering the number sylas 24 14,743 Apr-02-2017, 01:09 PM
Last Post: sparkz_alot
  How can I make a sentinel value NOT be initialized in a class/method - OOP? netrate 2 3,484 Jan-14-2017, 07:34 AM
Last Post: stranac

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020