Shadow Sage - 1 year ago 66

Python Question

I'm trying to find the smallest number where you can enter as many number and when you enter -1 it breaks.

`a=int(input("What is your number of choice? "))`

b=int(input("What is your number of choice? "))

c=int(input("What is your number of choice? "))

d=int(input("What is your number of choice? "))

smallest=a

if (b < smallest):

smallest=b

while(True):

smallest =int( input("What is your number of choice? "))

if (smallest == -1):

break

if (c < smallest):

smallest=c

while(True):

smallest =int( input("What is your number of choice? "))

if (smallest == -1):

break

if (d < smallest):

smallest=d

while(True):

smallest =int( input("What is your number of choice? "))

if (smallest == -1):

break

print(smallest, " is smallest of the numbers you chose")

I can't figure out how to fix it.

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

You need to set up a loop to allow the user to enter multiple values. keeping track of these values can be done using a list, and appending each input to it as follows:

```
all_inputs = []
val = int(input('Enter a number (or -1 to finish):'))
while val != -1:
all_inputs.append(val)
val = int(input('Enter a number (or -1 to finish):'))
print(str(min(all_inputs)) + ' is the smallest of your numbers')
```

`min`

can efficiently find the smallest value input.

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**