Home > Net >  2 minimum in Python
2 minimum in Python

Time:10-26

I have a program that asks me for 5 numbers and then prints the minimum. But now, I need a program that writes the minimum and the second minimum.

train=[]
min=100
for i in range(5):
    train.append(int(input("Enter a number")))
for carriage in train:
    if min>carriage:
        min=carriage
print("Minimum is ",min)

Can somebody please help me?

CodePudding user response:

train=[]
min1 = 100 #only 100, u sure?
min2 = 100
for i in range(5):
    train.append(int(input("Enter a number")))
for carriage in train:
    if min2 > carriage:
        min2 = carriage
        if min2 < min1: 
            min1, min2 = min2, min1
print("Minimum is ", min1, min2)
  • Related