How do I find the smallest number in a list of random integers on Python without using min()?
Question: I'm trying to figure out why this code isn't working! The only part not
working is the smallestNumber, it always comes back at zero? What am I doing
wrong?

    
    
    import random
    
    X  = random.randint(10,15)
    
    pickedNumber =int( input("Please enter a number: "))
    
    print("Generating", (pickedNumber), "random Numbers between 20 and 50:")
    
    for numberCount in range(1,pickedNumber+1):
    
        numberCount = random.randint(20,50)
        sum = 0
        sum += numberCount
        print(numberCount)
    
    print('The sum = ',sum)
    print('the average = ', sum/pickedNumber)
    
    for pickedNumber in range(0,X,1):
        number  = random.randint(20,50)
    
        if pickedNumber== 0 or pickedNumber < smallestNumber:
    
           smallestNumber = pickedNumber
    
    print('The smallest = ',smallestNumber)
    


Answer: There are several problems with your code that I won't address directly, but
as for finding the smallest item in a list of integers, simply sort the list
and return the first item in the list:

    
    
    some_list = [5,7,1,9]
    sorted_list = sorted(some_list)
    smallest = sorted_list[0]
    >>> smallest
    1
    

You don't necessarily need to create a second list to store the sorted result,
it is simply there to illustrate the difference.

EDIT: You could also just store the first random int generated as
`smallestNumber` and then as each new random int is created, compare it to
`smallestNumber` and if the new int is smaller, set `smallestNumber` to it.

Example:

    
    
    //stuff to generate random int done here
    smallest = new_random_int
    
    //generate the next random int
    if next_random_int < smallest:
        smallest = next_random_int
    

And so on, where `new_random_int` is the very first random integer you
generate, and `next_random_int` is any random int you generate after that.

Also, welcome to Stack Overflow!

