[Python] For Loops in Python (Output Smallest Input)

Discussão em 'Python' iniciado por Stack, Fevereiro 10, 2025.

  1. Stack

    Stack Membro Participativo

    Okay so I am practicing for loops in Python and I was wondering how could I make a user input 10 intergers then it would output the smallest one. I would know how to do this with a while loop for example:

    Smallest = 0
    count = 0
    while count < 10:
    Number = int(input("Enter a number >> "))
    if Number < Smallest:
    Smallest = Number
    count = count + 1

    print("{0} is the biggest value you have entered".format(Smallest))


    But how do I do it in a for loop format? Here's what I have so far:

    for i in range(10):
    Number = int(input("Enter a Number >> "))
    if Number < Smallest:
    Smallest = Number

    print("{0} is the smallest value you have entered.".format(Smallest))

    Continue reading...

Compartilhe esta Página