gpt-3.5-turbo-0613· OpenAI WildChat-4.8M (AI2)
how to add 10 random integer numbers into a list with for loop python
- User
how to add 10 random integer numbers into a list with for loop python
- 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
randommodule. Then, we create an empty list calledrandom_numbers.Next, we use a for loop that iterates 10 times (using
range(10)). Within each iteration, we use theappend()method to add a random integer number generated byrandom.randint(1, 1000)to therandom_numberslist.Finally, we print the
random_numberslist to see the 10 random integer numbers added to it.