I'd like to have only one Python random number occurrence, but what's wrong?

Asked 2 weeks ago, Updated 2 weeks ago, 1 views

import random
a = random.randrange(1,101)
def print_rand(n):
    for i in range(3):
        a = random.randrange(1,101)


2022-09-20 10:27

1 Answers

The question is how to get it back and how to use it. Let's just make it up without knowing your Python learning progress:

import random

# If you receive the number n, you take the number from 1 to 101 n times and return the list
def get_randoms(n):
    return list(map(lambda x: random.randrange(1, 101), range(n)))

# Can cause even 17 instead of 3
r3 = get_randoms(3)
r17 = get_randoms(17)

PS. To answer the question "what's wrong" itself, the print_land function you created is:

The part is not correct.

2022-09-20 10:27

If you have any answers or tips

© 2022 pinfo. All rights reserved.