Write a program in file MinMax.py that accepts an arbitrary number of integer inputs from the user and prints out the minimum and maximum of the numbers entered. The user will end the input loop by typing in the string 'stop'. When the user enters 'stop' your program should print out the minimum integer entered and the maximum integer entered. If the user enters 'stop' immediately (i.e., before any numbers are entered), you'll print a slightly different message. See the examples below: You can assume that the values entered are integers (positive, negative or zero) or the string 'stop' (lowercase). You don't have to validate the inputs. > python Min Max. py
Enter an integer or 'stop' to end: stop You didn't enter any numbers > python Min Max. py
Enter an integer or 'stop' to end: -10
Enter an integer or 'stop' to end: 0 Enter an integer or 'stop' to end: +42
Enter an integer or 'stop' to end: 87 Enter an integer or 'stop' to end: -100
Enter an integer or 'stop' to end: stop The maximum is 87 The minimum is -100

Respuesta :

Answer:

The program is as follows:

numlist = []

num = input("'stop' to end: ")

while not (num == "stop"):

   numlist.append(int(num))

   num = input("'stop' to end: ")

   

if len(numlist) == 0:

   print("You didn't enter any numbers")

else:

   print("The maximum is "+str(max(numlist))+" and The minimum is "+str(min(numlist)))

Explanation:

This declares an empty list

numlist = []

This prompts the user for input

num = input("'stop' to end: ")

This loop is repeated until the user enters 'stop'

while not (num == "stop"):

This appends the input to the list

   numlist .append(int(num))

This prompts the user for input

   num = input("'stop' to end: ")

   

If the length of the list is 0, then the user entered no input

if len(numlist) == 0:

   print("You didn't enter any numbers")

If otherwise, this prints the min and the max

else:

   print("The maximum is "+str(max(numlist))+" and The minimum is "+str(min(numlist)))

The program that accepts an arbitrary number of integer inputs from the user and prints out the minimum and maximum of the numbers entered is as follows:

numbers = []

x = input("Enter an integer and stop to end: ")

while not(x == "stop"):

    numbers.append(int(x))

    x = input("Enter an integer and stop to end: ")

if len(numbers) == 0:

    print("You didn't enter any numbers ")

else:

    print(f"The maximum number is {max(numbers)} and the minimum number is {min(numbers)}")

Code explanation:

The code is written in python

  • The first line of code, we declared a variable named numbers and it is an empty list for storing our integers.
  • The variable x is stores the user input
  • while the user's input is not lowercase "stop", the user's input is appended to numbers.
  • Then the program ask for the users input as long as it is an integers input
  • if the length of the list is 0, then we print a statement to ask the user to enter a number.
  • Else we print the maximum and minimum number of the user's input.

learn more on python code here: https://brainly.com/question/19175881

Ver imagen vintechnology
Ver imagen vintechnology