Python Forum
finding the minimum value out of a set of inputs
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
finding the minimum value out of a set of inputs
#1
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)
Reply
#2
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? ')
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to collect all integers with minimum number of rounds? meknowsnothing 6 3,174 Jun-11-2019, 08:36 PM
Last Post: jefsummers
  Storing Minimum List of values from a recursive function sigsegv22 1 2,498 Sep-10-2018, 01:25 PM
Last Post: ichabod801
  maximum and minimum element from the list and return output in dict MeeranRizvi 1 3,699 Jan-02-2017, 02:12 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020