Python Forum
finding the minimum value out of a set of inputs - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: finding the minimum value out of a set of inputs (/thread-13752.html)



finding the minimum value out of a set of inputs - kannan - Oct-30-2018

so here is the question.
Translate the following pseudocode for finding the minimum value from a set of inputs into a Python program.
Set a Boolean variable "first" to true.
While another value has been read successfully
If first is true
Set the minimum to the value. Set first to false.
Else if the value is less than the minimum Set the minimum to the value.
Print the minimum.

This is what I have so far but it currently takes the input and repeats indefinitely can anyone give thoughts or suggestions on what I'm missing from where?

#input value and setting boolean variable "first" to true
first = True

string=input("Please enter any numbers and -1 to finish:")


#initialize first to true
i = 0

#find the minimum value until sentinel is entered
while i < len(string):
     if first == True:
         minimum=string
         first = False
     elif string < minimum:
         minimum = string
     print(minimum)



RE: finding the minimum value out of a set of inputs - ichabod801 - Oct-30-2018

The reason your loop goes on forever is that you never change either string or i in the loop. So the condition in the while statement never changes.

pseudocode Wrote:While another value has been read successfully

This says to me that you want to get a new input each time through the loop. But you don't have an input inside the loop. You need one inside the loop, so you have a changing value for your while condition. However, it seems from the question in the input that the while condition should be looking for -1. I think the pseudocode it talking about this kind of structure:

answer = input('Keep going? ')
while answer != 'no':
    print('okay')
    answer = input(Keep going? ')