In: Computer Science
Write a script that finds the smallest of several nonnegative integers. Assume that the first value read specifies the number of values to be input from the user.
Hint: No need for Array declaration. Think like a while loop and iterate as many number as users will input. Then keep a temporary variable to keep track of the minimum.
Thanks for the question. Here is the completed python script for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. Thanks! =========================================================================== # that the first value read specifies the number of values to be input from the user. number_of_values = int(input('Enter the number of values: ')) min_number = int() # Then keep a temporary variable to keep track of the minimum. counter = 0 # A while loop and iterate as many number as users will input. while counter < number_of_values: number = int(input('Enter a non-negative number:')) if counter == 0: min_number = number elif min_number > number: min_number = number counter += 1 print('The smallest number entered was', min_number)
============================================================