# 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)
print_rand(3)
print(f'{a}')
``````

python

2022-09-20 10:27

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)
print(r3)
r17 = get_randoms(17)
print(r17)
``````

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

Popular Tags
python x 4520
android x 1589
java x 1455
javascript x 1363
c x 881
php x 682
html x 629
swift x 586
ios x 538
mysql x 397