Feb-14-2019, 02:49 AM

Hi, I'm making a program that generates a given quantity of numbers randomly and prints them, but I don't understand why I get this error:

The code:

The error:

The code:

from random import randint # n: normal, generates odd and even numbers. def n_repeated(q_of_nums, minimum_number, maximum_number): """Generates odd and even numbers, they can be repeated.""" print("The generated numbers are:") for i in list(range(q_of_nums)): x = randint(minimum_number, maximum_number) return def n_nonrepeated(q_of_nums, minimum_number, maximum_number): """Generates odd and even numbers, they can't be repeated.""" printed_numbers = [] print("The generated numbers are:") while printed_numbers < q_of_nums: for i in list(range(q_of_nums)): x = randint(minimum_number, maximum_number) if x in printed_numbers: continue else: print(x, end=' ') printed_numbers.append(x) n_repeated(6, 40, 1)

The error:

```
Error:
The generated numbers are:
Traceback (most recent call last):
File "test.py", line 27, in <module>
n_repeated(6, 40, 1)
File "test.py", line 10, in n_repeated
x = randint(minimum_number, maximum_number)
File "C:\Users\Franc\AppData\Local\Programs\Python\Python37-32\lib\random.py", line 222, in randint
return self.randrange(a, b+1)
File "C:\Users\Franc\AppData\Local\Programs\Python\Python37-32\lib\random.py", line 200, in randrange
raise ValueError("empty range for randrange() (%d,%d, %d)" % (istart, istop, width))
ValueError: empty range for randrange() (40,2, -38)
```

Thanks in advance for your help.