Feb-19-2019, 09:24 PM
Hi, i'm making a program that is supposed to randomly generate numbers between the parameters given.
I just copied a bit of the code to show the problem:
Also if you want to check the whole code you can go to: https://github.com/fwendeburg/random-num...evelopment
Thanks in advance!
I just copied a bit of the code to show the problem:
while True: command = input("\nEnter command: ") # Depending of the command that has been entered do the # thing related to the command. if command.lower() == 'help': show_help() if command.lower() == 'integer': while True: type_of_nums = input(type_of_nums_prompt) if type_of_nums == 'back': break if type_of_nums.lower() == 'e': repeated_q = input("Can the numbers be repeated? (y/n) ") if repeated_q.lower() == 'y': try: nums_to_gen = input(nums_to_gen_prompt) nums_to_gen = int(nums_to_gen) min_num = input(min_num_prompt) min_num = int(min_num) max_num = input(max_num_prompt) max_num = int(max_num) if max_num == 0: print("Thats not a valid number!\n") break except ValueError: if nums_to_gen == 'back' or min_num == 'back' or max_num == 'back': break else: print("That is not a number!\n") continue else: e_repeated(nums_to_gen, min_num, max_num) breakAnd this is the error:
Error:Welcome to Random Number Generator v1.0
Enter <help> for a list of commands and <quit> to exit the program.
Enter command: integer
What kind of number should the program generate? e
Can the numbers be repeated? (y/n) y
How many numbers do you want to generate? qfef
Traceback (most recent call last):
File "main.py", line 39, in <module>
nums_to_gen = int(nums_to_gen)
ValueError: invalid literal for int() with base 10: 'qfef'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 48, in <module>
if nums_to_gen == 'back' or min_num == 'back' or max_num == 'back':
NameError: name 'min_num' is not defined
As you can see in the first code the min_num variable is defined but it wont work when i use it in the if test.Also if you want to check the whole code you can go to: https://github.com/fwendeburg/random-num...evelopment
Thanks in advance!