Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does the function fit in? #15

Open
Iadam12 opened this issue Sep 26, 2017 · 6 comments
Open

How does the function fit in? #15

Iadam12 opened this issue Sep 26, 2017 · 6 comments

Comments

@Iadam12
Copy link

Iadam12 commented Sep 26, 2017

I'm struggling on this one. What is the function supposed to invoke?

@johnylemony
Copy link

It requires you to append data to hungry list and then return that list.

At least that is what worked for me

@ericericdodo
Copy link

I need help as well,
I am creating an empty list for hungry_list and then appended the hungry_list later on...
image
Can anyone tell me what I am doing incorrectly?

@IAMTARA
Copy link

IAMTARA commented Sep 28, 2017

you are defining hungry_list as an empty list. The 2nd paragraph is defining append_to_list as a command to print hungry_list which is an empty list at this point. In the final part you're telling it to ad "" to that empty list.
Regardless of what values you put in append_to_list you are going to always get [""] as an answer.

What I did was look at it as defining append_to_list(a, b). Where a is going to be a list, and b is going to whatever value that the code will append to list a. You don't need to define a or b (or in this case hungry_list and data) because their values are determined by whatever two things you put in parentheses in your test functions.

@jamesislike
Copy link

Not sure why my code isn't working....

test_append_empty_list = []
test_append_bigger_list = ['pizza','nachos']

def append_to_list(test_append_empty_list,b):
return (test_append_empty_list.append(b))

append_to_list(test_append_empty_list,"list food")
append_to_list(test_append_bigger_list,'chips')

print(test_append_empty_list)
print(test_append_bigger_list)

@ajtran303
Copy link

jamesislike

Try debugging your code in pythontutor.com

When I have been writing functions, it's been useful to me to look at the examples and work backwards from there.
The function append_to_list is called in the second line of the example:

a_list = ['pizza', 'bacon']
modified_list = append_to_list(a_list, 'hamburguer')
print(modified_list) # ['pizza', 'bacon', 'hamburguer']

So when you define the function it is supposed to look at any list, a_list in the example, and add data to that list and then finally return the list.

In the example's second line, the function append_to_list is called and ['pizza', 'bacon'] becomes ['pizza', 'bacon', 'hamburguer'].

@illya2412
Copy link

def append_to_list(hungry_list, data):
hungry_list.append(data)
return(hungry_list)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants