Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

2 minimum in Python

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading