Question

In: Computer Science

Write a program that uses a loop to read 10 integers from the user. Each integer...

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.

Solutions

Expert Solution

# 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


Related Solutions

Write a C program that uses a loop which prompts a user for an integer 10...
Write a C program that uses a loop which prompts a user for an integer 10 times and stores those integers in an array. The program will print out the numbers entered by the user with a comma and a space separating each number so the numbers can be read easily. The program will then calculate and print out the sum, integer average and floating point average (to 4 decimal points) of the numbers in the array. The information being...
Write a program that uses a while statement to read integers from the user and prints...
Write a program that uses a while statement to read integers from the user and prints the sum, average, and largest of these numbers. The input should terminate if the user enters 999. The average should be output with 4 digits of precision. c++ please ASAP
Problem description Write a program that uses a loop to read integer values from the standard...
Problem description Write a program that uses a loop to read integer values from the standard input stream. Each non-zero value, x, is the first number of a sequence. Define a0 = x; an+1 = an / 2 if an is even; an+1 = 3 * an + 1 if an is odd. Then there exists an integer k such that ak = 1. For each non-zero value of x, the program outputs the integer k such that ak =...
Write a program that uses a while loop with a priming read to ask the user...
Write a program that uses a while loop with a priming read to ask the user to input a set positive integers. As long as the user enters a number greater than -1, the program should accumulate the total, keep track of the number of numbers being entered and then calculate the average of the set of numbers after the user enters a -1. This is a sentinel controlled-loop. Here is what a sample run should look like: Enter the...
Write MIPs program that will read two integers from the user and compute for the sum...
Write MIPs program that will read two integers from the user and compute for the sum and difference of the two integers. Ask the user whether he wants to repeat the program : "[Y/y] / [N/n] ?".
Write an assembly program (Data and Code) that uses loop to read 10 numbers and output...
Write an assembly program (Data and Code) that uses loop to read 10 numbers and output the largest of those numbers, you can assume any length for those numbers. 80x86 assembly language
Write a PYTHON program that uses a while loop to prompt for 5 integers. If the...
Write a PYTHON program that uses a while loop to prompt for 5 integers. If the number is equal to 99, display "Ninety-nine", otherwise display "no-match". If the number is equal to 75, display "Seventy-five", otherwise display "no-match".
Using a while loop. Write a JAVA program that asks a user for an integer between...
Using a while loop. Write a JAVA program that asks a user for an integer between 1 and 9. Using the user input, print out the Fibonaccci series that contains that number of terms. Sample output: How many terms would like printed out for the Fibonacci Sequence? 7 Fibonacci Series of 7 numbers: 0 1 1 2 3 5 8
Write a C++ program to read in a list of 10 integers from the keyboard. Place...
Write a C++ program to read in a list of 10 integers from the keyboard. Place the even numbers into an array called even, the odd numbers into an array called odd, and the negative numbers into an array called negative. Keep track of the number of values read into each array. Print all three arrays after all the numbers have been read. Print only the valid elements (elements that have been assigned a value). a. Use main( ) as...
*JAVA PROGRAM* Write a do loop that prompts a user to enter an integer between 1...
*JAVA PROGRAM* Write a do loop that prompts a user to enter an integer between 1 and 100 inclusive. The user will be repeatedly prompted until they input a valid integer.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT