2 minimum in Python

Question:

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?

Asked By: Michal Dostal

||

Answers:

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)
Answered By: Kaktuts
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.