Help with ValueError using ranint from random. - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Help with ValueError using ranint from random. (/thread-16089.html) |
Help with ValueError using ranint from random. - FWendeburg - Feb-14-2019 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: 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: Thanks in advance for your help.
RE: Help with ValueError using ranint from random. - Larz60+ - Feb-14-2019 print values of minimum_number and maximum_number just before executing line 10 RE: Help with ValueError using ranint from random. - ichabod801 - Feb-14-2019 You're trying to get randint(40, 1). But 40 > 1, so there are no possible numbers randint could return. The first number needs to be less than the second number. |