In: Computer Science
Write a program that uses a loop to read 10 integers from the user. Each integer will be in the range from -100 to 100. After all 10 integers have been read, output the largest and smallest values that were entered, each on its own line in that order.
Avoiding using the max or min functions from Python, and definitely use a loop to read the integers instead of 10 input statements.
# Reading first value n = int(input()) # Assuming first value as maxValue maxValue = n # Assuming first value as minValue minValue = n # Looping through for 9 times for i in range(9): # Reading remaining values from user n = int(input()) # if the newly entered value is greater than the current maxValue if(maxValue < n): # Then updating maxValue to current value maxValue = n # if the newly entered value is less than the current minValue if(minValue > n): # Then updating minValue to current value minValue = n # Printing maxValue print(maxValue) # Printing minValue print(minValue)
Note: Green text in the output screen is the input and last two numbers are largest and smallest among 10 input integers