Ask Question
4 February, 15:31

Write and test a Python program to find and print the smallest number in a set of integer numbers. The program should read input numbers until it reads a negative number. The negative number serves as a sentinel or marker telling the program when to stop reading numbers. The smallest of all numbers input as well as how many numbers were read (not considering the sentinel number) should be printed.

+5
Answers (1)
  1. 4 February, 15:59
    0
    numbers = []

    count = 0

    while True:

    number = int (input ("Enter a number: "))

    if number < 0:

    break

    else:

    numbers. append (number)

    count + = 1

    min_number = min (numbers)

    print (str (min_number) + " was the smallest among " + str (count) + " entered numbers.")

    Explanation:

    Initialize an empty array, to hold the entered numbers, and count as 0

    Create a while loop that iterates until a specific condition is met

    Inside the loop, ask the user to enter the numbers. When the user enters a negative number terminate the loop. Otherwise, add the entered number to the numbers array and increment the count by 1.

    When the loop is done, find the smallest of the number in the numbers array using min method and assign it to the min_number.

    Print the min_number and count
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write and test a Python program to find and print the smallest number in a set of integer numbers. The program should read input numbers ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers