Answer to Question #287364 in Python for umair

Question #287364

Create a list named nums and initialize it with at least 3 numbers [1,2,3]. Create a list named

hobbies, initialize it with at least 3 of your hobbies, for example ['Playing Cricket', 'Reading

Books', 'Cooking']. Iterate over the list nums and print hobbies for each list element, so that

the output looks like this:


1
Expert's answer
2022-01-14T04:36:36-0500
import random


# Method 1: List Comprehension Random Float List [0, 1]
randlist1 = [random.random() for _ in range(10)]


# Method 2: List Comprehension Random Int List [0, 999]
randlist2 = [random.randint(0, 999) for _ in range(10)]


# Method 3: For Loop Random Int List [0, 99]
randlist3 = []
for _ in range(10):
    randlist3.append(random.randint(0, 99))


# Method 4: random.sample()
# Generate 10 random numbers between 0 and 20 (included)
randlist4 = random.sample(range(20), 10)




print(randlist1)
print(randlist2)
print(randlist3)
print(randlist4)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS