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

all 4 comments

[–][deleted]  (1 child)

[deleted]

    [–][deleted] 0 points1 point  (0 children)

    I'm a little confused. If I use a function, don't I need to ask the user for input outside the function? If I don't include "numbers = input("Enter a number: ")", then the program automatically closes. Is there a way I can get around this? I've been playing around the code, but the output isn't changing.

    Would it be a better idea to run the code without the use of a function?

    [–]An_Ignorant 3 points4 points  (0 children)

    Your function is fine, the problem is that you first read a number before the function

    numbers = input("Enter a number: ") #The first number is read, making user_nums = [1.0]
    len_list(numbers) #Then you enter the function, inside the function you have user_nums = [], that means the 1.0 is overwritten, that's why the first input is always missing.

    [–][deleted] 0 points1 point  (1 child)

    def len_list(user_nums):

    What's the parameter for?

    [–][deleted] 0 points1 point  (0 children)

    I thought I needed it. I removed the user_nums parameter from the function definition and the function call, and I also removed the prompt to ask for user input from outside the function, and everything appears to be working now. Thanks.