# How to print min() from input intergal values in while-loop?

Hello,

the while-loop works perfectly, but I have no idea how to make a list like this:
min (x, y, z, …). The loops just asks for numbers, nothing else.

``````print("This programme searches the smallest integral of the integrals you gave.")
number = input("Please give an integral between 1-100 (-1 ends): ")
while 0 < int(number):
if 0 < int(number) < 101:
number = input("Please give an integral between 1-100 (-1 ends):  ")
else:
print ("The number is not on the asked difference, -1 ends.")
number = input("Please give an integral between 1-100 (-1 ends):  ")
print("Of the numbers you gave, this was the smallest: ", min(unclear content)
print("Thank you for using this programme.")
``````

Thank you in advance for any help.

Okay let’s try this:

``````# As the person would give numbers so use the for loop instead will help you a lot:

elements= int(input("How many nums you have? "))

free_list=[]

for i in range (elements):
numbers= int(input("What are the nums: "))
free_list.append(numbers)
print(min(free_list))

``````

Try that one as the while loop U used has no stop only if the person chose a number < 0!
other than that the loop will always ask him for a number

Thank you.

As it is unknown how many integral numbers the user will input I wonder how this information would be inputted. I will research this further.

The word you’re looking for is integer. An integral is something else.

1 Like

Well, your code stops when it sees a number < 0, and Ammar’s code stores the numbers in a list. You just need to combine the two.

1 Like

I got your question sorry I was thinking that you want another way for loop
try this:

``````free_list=[]
numbers= int(input("What are the nums: "))
while numbers > 0:
numbers= int(input("What are the nums: "))
free_list.append(numbers)
print((free_list))
print(f'The smallest value is: {min(free_list)}')

``````
1 Like

Hello,

so I made a new version of this.

A problem is prevalent. The code, instead of doing either “if” or “else”, the programme does both. This leads to that -1 in included in the list.append(number), which should not be possible, and thus the smallest integer becomes -1.

Note: I am not allowed to write

``````print((list))
``````

as the exercise does not allow that line. I need to have 100% the same output as the course intends.

``````print("This programme gives the smallest integer of all the integers you input")
number = input("Please give an integer between 1-100 (-1 ends): ")
while 0 < int(number):
if 0 < int(number) < 101:
number = input("Please give an integer between 1-100 (-1 ends): ")
list.append(number)
else:
print ("The number was not between the given criteria 1-100. Please give a new number between 1-100, -1 lopettaa.")
number = input("Please give an integer between, 1-100 (-1 ends): ")
list.sort()
print("Of the numbers you gave the smallest integer is", min(list))
print("Thank you for using this programme.")
``````

Your code first checks whether the number is between 1 and 100, then it asks the user for a new number, and always appends it to the list even if it is -1.

``````    if 0 < int(number) < 101:
number = input("Please give an integer between 1-100 (-1 ends): ")
list.append(number)
``````

By the way, you don’t need to sort the list if all you need is the min. `min(list)` will work even if the list is unsorted.

1 Like

So, because `list.append(number)` appears right away after the input is given, the
`if 0 < int(number) < 101` does not activate? I see. Thank you.

No, the `if 0 < int(number) < 101` activated. But after it runs, you change the number. Now that condition may no longer hold.

Suppose you are a bouncer at a nightclub. The condition is you only allow in people who are over 18. I walk up to you and show you my ID, you look at it and say “You are over 18, so you’re allowed in” but (this is the bug in your code!) instead of letting me in, you push me to the side and allow the next person in without looking at their ID.

1 Like

I could not really understand your explanation for now, but after some changes I got the code to work.

Thank you to everyone on this thread.

1 Like