Generate n integers randomly for Python

Asked 2 years ago, Updated 2 years ago, 118 views

X = []

for x in range (n): X.appned(random.randint(-999,999))

When I try to randomly generate n integers in Python, I try to use randint, but I made an error to randomly generate n integers, and I saw that n was not defined, so how should I define it here?

python random

2022-09-22 18:21

1 Answers

n = value

Or are you trying to reuse it as needed? Then I think you should look for a function

import random

X = []

n = 5

for x in range (n):
  X.append(random.randint(-999,999))

print(X)


2022-09-22 18:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.