I'm writing a program that takes 2 arguments, a list of numbers 1-10. and a variable of n = 6. I made a function that takes in the two arguments and returns the values that are less than 6 into a new list. But I'm trying to print the numbers that are less than 6. It's printing the index numbers. Is there a quick fix or simple way to convert the items in input_list into integers to print as a result?
it's printing [0,1,2,3,4] but I want it to print [1,2,3,4,5]
Thanks for your help!
* Python3 code *
This program takes in two arguments, a number, and a list. A function should return a list of all numbers less than the number
def main():
#initialize a list of numbers
input_list = [1,2,3,4,5,6,7,8,9,10]
n = 6
print("List of Numbers:")
print(input_list)
results_list = smaller_than_n_list(input_list,n)
print("List of Numbers that are smaller than 6:")
print(results_list)
def smaller_than_n_list(input_list,n):
# create an empty list
result = []
for num in range(len(input_list)):
if n > input_list[num]:
result.append(num)
return result
main()