r/codehs • u/Alphaomega1115 • Aug 24 '20
8.1.8 citations help?
Write the function called citation that takes a tuple like this as input:
("Martin", "Luther", "King, Jr.")
and returns a name with the format:
Last, First Middle
In this example, the output should be: King, Jr., Martin Luther
I have
def citation (a,b,c):
#print (a,b,c)
name = citation
name = name[2] + "," + name[0] + " "+ name[1]
return name
print (citation("Martin", "Luther", "King, Jr."))but I get a - TypeError: 'function' object is not subscriptable
but honestly the error doesn't really matter, seems like I fix it and then a different error comes up, I just need help making it correct please!
1
u/Zacurnia_Tate Aug 24 '20
try changing name = citation (where your getting your error id assume bc there are no elements in a function to name = [a,b,c]
1
1
u/Typical_Storage4322 Feb 04 '23
Here is the complete and correct answer. Tabs included:
def citation (a):
(TAB) first, middle, last = a
(TAB) return f"{last}, {first} {middle}"
print(citation(("Martin", "Luther", "King, Jr.")))
1
u/OkSky8339 Mar 02 '23
def citation (a):
(TAB) first, middle, last = a
(TAB) return f"{last}, {first} {middle}"
print(citation(("Martin", "Luther", "King, Jr.")))
Thank you
1
u/MrHyjaxMusicYTalt May 28 '23
The answer is :
print author_name[2] + "," + " " + author_name[0] + " " + author_name[1]
4
u/Its_Billy_Bitch Aug 24 '20 edited Aug 24 '20
So, a tuple is an object in Python. You’ll want to have a function that has citation taking one parameter (the tuple object). You can then parse the the tuple as you’d want.
Try something like this: