我正在写一个程序,该程序应该接受条目并以特定的修改后的APA形式返回APA引文。我意识到我只需要用斜体字打印文本的某些部分。现在,我的程序只是做一个输入,询问你是否有特定的信息,如果你有,它会要求它,格式化它,并把它放在一个列表(fullCitation),我最终会打印(“.join(fullCitation)),然后打印整个citation。我需要斜体的第一部分是出版商名称,我可能需要将其作为斜体文本存储在完整的引文列表中。我可以想出一种方法,使用索引范围并只使用斜体来打印它,但我真正需要知道的是如何在Python中打印/存储斜体文本。我使用的是语言版本3.0。我在Windows10上使用EclipseJuno。这是我的代码:welcome="Welcome to the research APA citation machine. If you want specific instructions, type help. If you are ready, type ready."
print(welcome)
type=input('web page=1, Journal=2. type your citation type number: ')
#asks citation type. only journal is available (work in progress)
fullCitation=[]
#this is the whole citation in a list. Everything gets appended in a certain order with spaces already formatted.
authorKnown=input("Is the author known? ")
if authorKnown.lower()=='yes':
authorNum=input('How many authors? ')
nameList=[]
for x in range(1,int(authorNum)+1):
first=input("First name: ")
firstInitial=first[0].upper()+'.'
last=input("Last name: ")
middleKnown=input('Is there a middle name? ')
if middleKnown.lower()=='yes':
middle=input("Middle name: ")
middleInitial=middle[0].upper()+'.'
fullName= last+', '+firstInitial+middleInitial
nameList.append(fullName)
if middleKnown.lower()=='no':
fullName=last+', '+firstInitial
nameList.append(fullName)
if len(nameList)==1:``
fullCitation.append(nameList[0])
if len(nameList)==2:
fullCitation.append(nameList[0]+'and'+nameList[1])
#just puts an "and" in between the two authors
if len(nameList)>=3:
nameListPunc=[]
for x in nameList[0:len(nameList)-2]:
nameListPunc.append(x+', ')
nameListPunc.append(str(nameList[len(nameList)-2])+', and '+str(nameList[len(nameList)-1]))
fullCitation.append("".join(nameListPunc))
#This is for when you need to list items like "a, b, c, and d"
if authorKnown.lower()=='no':
pass
#asks if author(s) are known and formats name(s)
pubYearKnown=input('Is the year of publication available? ')
if pubYearKnown.lower()=='no':
fullCitation.append('(n.d.). ')
if pubYearKnown.lower()=='yes':
pubYear=input('Publication year: ')
fullCitation.append('('+pubyear+'). ')
#asks if publication year is known and formats it
#this is not complete. I still need to code for title, journal name(italics), volume number(italics), and page numbers