Untitled
unknown
python
3 years ago
2.5 kB
9
Indexable
# Ethan Walton # 16 March 2022 reference = input('Enter the reference:\n') # Extract the authors from the input string authors = reference[0:reference.find(' (')].lower() authorsReform = '' # Count the number of authors in the list based on the amount of commas numAuthors = authors.count(',') + 1 i = 1 refReform = '' # Capitalize Author Names while i <= numAuthors: # If it is the last author take the rest of the string if i == numAuthors: currAuthor = authors[0:] else: # Otherwise, take the beginning of the string up until the next author currAuthor = authors[0:authors.find(',')] # Remove the extracted author from the list of authors authors = authors.replace(currAuthor+', ','') # Replace the first letter of the author name with a capital currAuthor = currAuthor.replace(currAuthor[0], currAuthor[0].upper()) # If the auther's full name is present, capitalize the first letter of both names if currAuthor.find(' ') > 0: # Take the first name, then add the first letter of the second name as a capital and then add the rest of the name currAuthor = currAuthor[0:currAuthor.find(' ')+1] + currAuthor[currAuthor.find(' ')+1:currAuthor.find(' ')+2].upper() + currAuthor[currAuthor.find(' ')+2:] if i == 1: # If it is the first author, add the authors formatted name to the reformatted string without a comma refReform = refReform + currAuthor else: # refReform = refReform + ', ' + currAuthor i += 1 # Find and add the year of the reference to the output refReform = refReform + reference[reference.find(' ('):reference.find(')')+2] title = reference # Extract everything after the year from the reference title = reference[reference.find(')'):] # Store everything after the title afterTitle = title[title.find(','):] # Store the title title = title[:title.find(',')] # Make the title lowercase to remove all possible capitals title = title.lower() # Capitalize the first letter of the title that comes after the year and then add the rest of the now lowercase title title = title[title.find(')')+2:title.find(')')+3].upper() + title[title.find(')')+3:] # Add the formatted title and rest of the reference to the output refReform = refReform + title + afterTitle # Output formatted reference print('Reformatted reference:\n', refReform, sep='')
Editor is loading...