Question

#APA citation style cites author names like this: # #  Last, F., Joyner, D., & Burdell,...



#APA citation style cites author names like this:

#

#  Last, F., Joyner, D., & Burdell, G.

#

#Note the following:

#

# - Each individual name is listed as the last name, then a

#   comma, then the first initial, then a period.

# - The names are separated by commas, including the last

#   two.

# - There is also an ampersand and additional space before

#   the final name.

# - There is no space or comma following the last period.

#

#Write a function called names_to_apa. names_to_apa should

#take as input one string, and return a reformatted string

#according to the style given above. You can assume that

#the input string will be of the following format:

#

#  First Last, David Joyner, and George Burdell

#

#You may assume the following:

#

# - There will be at least three names, with "and" before

#   the last name.

# - Each name will have exactly two words.

# - There will be commas between each pair of names.

# - The word 'and' will precede the last name.

# - The names will only be letters (no punctuation, special

#   characters, etc.), and first and last name will both be

#   capitalized.

#Write your function below!


#Below are some lines of code that will test your function.

#You can change the value of the variable(s) to test your

#function with different inputs.

#

#If your function works correctly, this will originally

#print: Last, F., Joyner, D., & Burdell, G.

print(names_to_apa("First Last, David Joyner, and George Burdell"))

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def names_to_apa(s):
#Split names separated by a comma
names = s.split(',')
n = len(names)

result = "" #To store final output

for i in range(n) :
   #Split names into first, lastname etc separated by space
   name = names[i].split(' ')

   #Remove empty spaces,also ignore the word 'and'
   if("" in name):
     name.remove("")
   if("and" in name):
     name.remove("and")

   #Append '&' if it is the last name
   if(i == n-1 and n>1):
       result = result + "& "

   #Append Last name and First name initial
   #name[-1] gives last index, name[0][0] = 1st character of 1st name
   result = result + name[-1] + ", " + name[0][0] + "."

   #Append a comma .
   if(i<n-1 and n>1):
     result = result + ', '

return result

####################### TEST #######################
print(names_to_apa("First Last, David Joyner, and George Burdell"))

Add a comment
Know the answer?
Add Answer to:
#APA citation style cites author names like this: # #  Last, F., Joyner, D., & Burdell,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In python,write a function nameSet(first, last) that takes a person's first and last names as input,...

    In python,write a function nameSet(first, last) that takes a person's first and last names as input, and returns a tuple of three strings: the first string gives the union of all letters in the first and last names (no duplication though). The second string gives the intersection of letters in the first and last names, i.e. the common letters. If there are no common letters, then the second string is empty (''). The third string gives the symmetric difference between...

  • Write a program that reads a person's first and last names, separated by a space. Then...

    Write a program that reads a person's first and last names, separated by a space. Then the program outputs last name, comma, first name. End with newline. Example output if the input is Maya Jones Tones, Maya import java . util·Scanner; public class SpaceReplace 4 public static void main (String [1 ares) f( Scanner scnr-new Scanner(System.in); String firstName; String lastName; Your solution goes here */ 10 12

  • Write a program that reads a person's first and last names, separated by a space. Then...

    Write a program that reads a person's first and last names, separated by a space. Then the program outputs last name, comma, first name. End with newline. Example output if the input is: Maya Jones Jones, Maya import java.util.Scanner; public class SpaceReplace {    public static void main (String [] args) {       Scanner scnr = new Scanner(System.in);       String firstName;       String lastName; //answer goes here//    } }

  • In C Write a function that asks for the user's first, middle, and last names. The...

    In C Write a function that asks for the user's first, middle, and last names. The names will be entered by the user on a single line and will be stored in three different C-strings. The program should then store, in a fourth array, the name arranged in the following manner: the last name followed by a comma and a space, followed by the first name and a space, followed by the middle name. For example, if the user entered...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • C++ Write a program that reads students’ names followed by their test scores from the given...

    C++ Write a program that reads students’ names followed by their test scores from the given input file. The program should output to a file, output.txt, each student’s name followed by the test scores and the relevant grade. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, testScore of type int and grade of type char. Suppose that the class has 20 students. Use an array of...

  • 1-which one the following is the correct APA citation style of a book? Last, F. M...

    1-which one the following is the correct APA citation style of a book? Last, F. M (year published), Publisher. Book. City, State Last, F. M (year published) Book. City, State: Publisher Last, F. M (year published) Book. Publisher City, State Last, F.M. Book (year published). City, State: Publisher 2-you are writing a research paper on the effects of advertisement on the living style of children, which of the following is a best search strategy? (Kids OR students) AND advertisement AND...

  • *****Requiremrnt: 1. Please do not use any array or arraylist 2. collects only a single String...

    *****Requiremrnt: 1. Please do not use any array or arraylist 2. collects only a single String input 3. uses at least 3 String methods 1) Just Initials: Print just the initials in upper case letters separated by periods 2) Last Name First With Middle Initial: Print the last name in lower case with the first letter capitalized, followed by a comma and the first name in in lower case with the first letter capitalized and then the middle initial capitalized...

  • in csis 152 style python programming language Read the initial employee information from a text file...

    in csis 152 style python programming language Read the initial employee information from a text file and store the employee information into a list of sublists called empRoster. Each sublist should contain [empID, name, payrate,hours] Here's an example of how empRoster will look: 111, "Sally Smith", 10, 401, 1222, "Bob Brown", 10, 42]1 The text file will be structured as shown below, where each line contains the employee id, employee name, payrate and hours. Each entry on the line is...

  • We are trying to make sure your passphrase is acceptable! Write a script that asks for...

    We are trying to make sure your passphrase is acceptable! Write a script that asks for an input string that will be used as your password. This input string will have three “words” separated by a space character. Each of these words has specific requirements, listed below. You must write a function for each requirement (three total functions). Make sure your functions follow the original template that provided. First Function: For the first word, you must check if it is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT