A
A
Astraithios2021-03-08 12:01:01
Python
Astraithios, 2021-03-08 12:01:01

Does not recognize a variable in the random module, how to fix it?

number_limits = random.randrange(num1, num2)

num1 == 2
num2 == 4


NameError: name 'num1' is not defined It is

necessary that the required values ​​are substituted in random.randrange(num1, num2), how to do this, please help?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
O
Osmanov Osman, 2021-03-08
@Astraithios

Two mistakes. One is that you have a procedural style of programming (this is not a bug) and therefore variables must be declared before calling the function. The second - you didn't announce it even after. What you have done is nonsense code.

num1 = 2
num2 = 4
number_limits = random.randrange(num1, num2)

Two is equal to the condition. You are comparing num1 to two and num2 to four. Which is also wrong, because the variables num1 and num2 are not declared.

R
Roman prV, 2021-03-08
@procheloVek

Variables must be declared before calling a function

A
Andrey Prenrek, 2021-03-08
@Frotryi

Decision:

num1 == 2
num2 == 4

number_limits = random.randrange(num1, num2)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question