65.6k views
1 vote
Make a list of 10000 random numbers from (1-100). Print all the indexes the number 89 is at.

This a python question. Copy-paste your answer directly from python
Your answer should be short. If your answer is wrong or is something random, I'll be reporting your answer
If you give me a good answer you'll get 50 points :)

1 Answer

4 votes

Answer:

import random

# Generate a list of 10000 random numbers between 1 and 100

random_list = [random.randint(1, 100) for i in range(10000)]

# Find the indexes where the number 89 appears in the list

indexes = [i for i in range(len(random_list)) if random_list[i] == 89]

# Print the indexes

print("The number 89 appears at the following indexes:")

print(indexes)

Step-by-step explanation:

This code uses a list comprehension to generate the list of random numbers and another list comprehension to find the indexes where the number 89 appears. The range(len(random_list)) function generates a sequence of integers from 0 to the length of the list minus 1, which are used as indexes to access the elements of the list. The if condition checks whether the element at the current index is equal to 89, and if so, the index is added to the indexes list. Finally, the print statement displays the list of indexes where the number 89 appears.

User Lewkka
by
7.9k points