Python: Loop Sentinel Value -
I should write a program that allows a user to enter a series of integers, then the signal-end of the 99 series After entering all the numbers, the program should enter the largest and smallest number.
This is what I have done so far:
def main (): user_input = 1 while user_input! = -99: user_input = int ("Enter your number or end-99.") Big = big (user_input) tinier = smallest (user_input) print ('biggest number is', bigger,' and The smallest is "small", ".") DEIF is the largest (number): largest = 0 if the number> largest: largest = number greatest DRF small number (number): minimum = 10000 if number & lt ; Smallest: smallest number = smallest ()
sensor value for any reason (-99) is entering the loop, I have no clue, and to become the lowest value. On top of that, the greatest value is never right, much appreciated!
Fast change to create your code to fix this
User_input! = -99: user_input = int (input ("own" Enter the number or end-99. ") If use_input == - 99: break greater = largest (user_input) tinier = smallest (user_input) print ('the largest number, big The problem is, if the user enters the -99, you complete the remaining rows for the iteration of the loop, and the smallest, "tiny,". " The problem is, We do. It will not end the while
loop until the next time, but already it has the largest
and small
on it, so it's the first time Has been written from.
Comments
Post a Comment