Skip to content
The Chat Archive
gpt-3.5-turbo-0613· OpenAI WildChat-4.8M (AI2)

how to add 10 random integer numbers into a list with for loop python

  1. User

    how to add 10 random integer numbers into a list with for loop python

  2. Assistant

    Here's an example of how to add 10 random integer numbers into a list using a for loop in Python:

    import random
    
    random_numbers = []
    
    for _ in range(10):
        random_numbers.append(random.randint(1, 1000))
        
    print(random_numbers)
    

    In this code, we first import the random module. Then, we create an empty list called random_numbers.

    Next, we use a for loop that iterates 10 times (using range(10)). Within each iteration, we use the append() method to add a random integer number generated by random.randint(1, 1000) to the random_numbers list.

    Finally, we print the random_numbers list to see the 10 random integer numbers added to it.