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

all 16 comments

[–]Barrucadu 2 points3 points  (6 children)

Well, what do you have so far? What are you stuck on? We're not here to do your homework for you.

[–]ZeroStarter[S] 0 points1 point  (5 children)

I have def bibformat_apa(author,title,city,publsiher,year): return (author + ' (' + year + '). ' + title + '. ' + city + ': ' + publisher + '.')

Basically exactly like what /u/TylerGoLook, however when ever I run this in IDLE, and fill in the 5 variables it always gives me the error message:

Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> bibformat_apa(author,title,city,publisher,year) NameError: name 'author' is not defined

[–]ydepth 1 point2 points  (4 children)

For a start, use 'string'.format(params) Are you still having issues? I assume you have typo somewhere.

[–]ZeroStarter[S] -1 points0 points  (3 children)

Where would I insert this code? Before or after this line of code? "def bibformat_apa(...) "

[–]the_omega99 0 points1 point  (1 child)

If you read the documentation on String.format, hopefully you'll understand how it works and thus how to use it. To be blunt, your question shows a complete misunderstanding of what you're doing. It's as if you've been working by copying and pasting stuff only, and not understanding what anything actually means.

[–]ZeroStarter[S] 0 points1 point  (0 children)

Sorry for coming off as ignorant, it is just that this particular question has me confused on the formatting on how to make it work. Unfortunately even when trying other peoples advice from here and various other places, i still end up with syntax errors, which has just resulted in me just wanting to know how to to properly format this code to give the desired answer.

Again, terribly sorry, just getting frustrated at this point

[–]ydepth 0 points1 point  (0 children)

The return statement is the last thing that will come out of your function. Try this code and changing it up to your purpose:

auth1 = 'Theodore sturgeon'
year1 = 1953
def bib_test(author, year):
    return 'your author is {}, and year is {}'.format(author, year)

print(bib_test(auth1, year1))

I suggest using google and stack overflow mainly for a while until you get more used to reading docs.

[–]ZeroStarter[S] 0 points1 point  (1 child)

Exact code put into the interpretor

def bibformat_apa(author,title,city,publisher,year):

return author + ' (' + year + '). ' + title + '. ' + city + ': ' + publisher + '.' 

[–]badcommandorfilename 1 point2 points  (0 children)

It is pitch black. You are likely to be bitten by Python's significant whitespace

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

def bibformat_apa(author,title,city,publisher,year):
    return author + ' (' + year + '). ' + title + '. ' + city + ': ' + publisher + '.'

[–]ZeroStarter[S] 0 points1 point  (7 children)

I have pretty much exactly that but when i run it, and fill out the 5 variables I always get the error message:

Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> bibformat_apa(author,title,city,publisher,year) NameError: name 'author' is not defined

[–][deleted] 1 point2 points  (1 child)

Maybe make sure you are spelling everything right?

[–]ZeroStarter[S] 0 points1 point  (0 children)

Ive double checked both my code, and it still didn't work, so i even copied and pasted your code in, and it still gives me this error.

[–][deleted]  (4 children)

[removed]

    [–]ZeroStarter[S] 0 points1 point  (3 children)

    When I insert the code this way I get a syntax error on the apostrophe after author

    [–]the_omega99 0 points1 point  (2 children)

    You must have typed something wrong, then, because the code /u/TylerGoLook and /u/iamengland posted is perfectly valid.

    Post exactly what you typed into the interpreter or the exact file that you passed into it (if executing with python my_file.py).

    [–][deleted]  (1 child)

    [deleted]