Right now I'm trying to write a program that takes 20 numbers, and can do a variety of tasks with those numbers, such as finding the smallest/largest integer, find the total, average, etc.
I have the core program working, but I'm trying to add an additional option that allows the user to select a range of numbers, and create a list of 20 values. As far as I know, I also have this written correctly.
The primary issue that I'm having, is that when I try to return the list so that it may be stored within the previously defined list, it won't store any of the values.
Here is the function that I wrote for a user to input their own 20 values:
#Get Number List
def input_numbers():
print("Please enter a series of 20 numbers, pressing enter after each number.")
numList=[int(input('Enter a number: ')) for i in range(20)]
return numList
This works like a charm, no questions asked.
On the other hand, this is my randomly generated list:
#Randomly generate 20 numbers.
import random
def randomly_generate():
number1= int(input("Please enter the lower number: "))
number2= int(input("Please enter the higher number: "))
numList=random.sample(range(number1, number2), 20)
print(numList)
return numList
To clarify: I am only printing within the function to see if the random number generator works, it is. It will print 20 values within the specified range.
However, when I return numList, it is not storing properly like the first function is. This causes issues for me, because I cannot perform my other functions with an empty list.
EDIT: Here is what caused the issue: I was returning the value, but not redefining numList, thus creating my issue.
elif choice == RANDOMLY_GENERATE:
randomly_generate()
#Randomly generate 20 numbers
#Import Random
import random
def randomly_generate():
number1= int(input("Please enter the lower number: "))
number2= int(input("Please enter the higher number: "))
numList=random.sample(range(number1, number2), 20)
print(numList)
return numList