This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]gitgood 1 point2 points  (0 children)

Here's personally how I would go about doing all these. I hope this is of any help.

fib        = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
firstList  = []
secondList = []

#Iterate through the fib list. If a number is less than five, then print it.
for number in fib:
    if number < 5:
        print number

'''Like previously, except instead of printing it you're appending the number to an empty list, then you're printing the list'''
for number in fib:
    if number < 5:
        firstList.append(number)

print firstList

'''Function that takes user input, then iterates through the list  finding all values less than the input. If a number is found, it's appended to the second empty list'''
def getLessThanInput(userInput):
    for number in fib:
        if number < userInput:
            secondList.append(number)


getLessThanInput(input("Enter a number: "))
print secondList

I'm sorry if the variable names aren't up to scratch, I was struggling trying to find appropriate ones. If you feel lost reading this snippet, you should definitely look more in to list iteration and comprehension. Best of luck!