用于图书发行过程的python程序

时间:2019-02-27 04:58:48

标签: python

对于图书馆图书的发行过程,我考虑以下信息 有关书籍的信息 线格式:登录号〜标题

有关借款人的信息 线格式:用户名〜全名

有关结帐的信息 行格式:用户名〜登录号〜到期日

我正在尝试编写一个Python程序来如上所述读取数据并打印出已签出的书的详细信息。每行应以以下格式描述一本当前发行的书:

截止日期〜名字〜登录号〜标题 输出应按截止日期的升序排序。对于同一日期到期的图书,请按全名的升序排列。

这里是样本输入及其对应的输出。 样本输入

书籍 APM-001〜高级药水 GWG-001〜食尸鬼的接缝 APM-002〜高级药水 DMT-001〜防御魔法理论 DMT-003〜防御魔法理论 GWG-002〜食尸鬼的接缝 DMT-002〜防御魔法理论 借款人 SLY2301〜汉娜·雅培 SLY2302〜Euan Abercrombie SLY2303〜斯图尔特·阿克利 SLY2304〜贝特拉姆·奥布里 SLY2305〜很 SLY2306〜马尔科姆·巴多克 SLY2307〜马库斯·贝尔比 SLY2308〜凯蒂·贝尔 SLY2309〜天狼星猎户座黑色 结帐 SLY2304〜DMT-002〜2019-03-27 SLY2301〜GWG-001〜2019-03-27 SLY2308〜APM-002〜2019-03-14 SLY2303〜DMT-001〜2019-04-03 SLY2301〜GWG-002〜2019-04-03 EndOfInput

示例输出

2019-03-14〜Katie Bell〜APM-002〜高级药水制作 2019-03-27〜Bertram Aubrey〜DMT-002〜防御魔法理论 2019-03-27〜Hannah Abbott〜GWG-001〜与食尸鬼合影 2019-04-03〜Hannah Abbott〜GWG-002〜与食尸鬼合影 2019-04-03〜斯图尔特·阿克利〜DMT-001〜防御魔法理论

def inp_borrower(l):
x=input()
while x!='Checkouts':
    x=x.split('~')
    x.append(0)    
    l.append(x)
    x=input()

def inp_books(checkout):
x=input()
while x!='EndOfInput':
    x=x.split('~')
    x=x[len(x)-2:]
    grade.append(x)
    x=input()
def checkout(x):
if x=='EndOfInput':
    return map(lambda x:x[1], sorted(map(lambda a:[map(int,a.split('-')),a], timestamps)))
def cal():
global li,grade
for i in li:   # i is a list containg the name and roll of a student
    j=0
    sum=0
    while j<len(grade):
        if i[0]==grade[j][0] :     # if the roll matchs
            sum=sum+com(grade[j][1])
            grade.pop(j)
            i[2]+=1
        else :
            j+=1
    if sum!=0 :
        i[2]=round(sum/i[2],2)
    print(i[0]+'~'+i[1]+'~',i[2],sep='')
li=[]             
grade=[]
x=input()
while x!='borrower':          
x=input()
stu_input(li)
li.sort()
inp_grade(grade)
cal()

我将不胜感激!请考虑到我真的是新手。我也不太确定要在函数内部包含函数。

谢谢!

2 个答案:

答案 0 :(得分:0)

def borrowers_input(b):
   x=input()
    while x!='Checkouts':
        x=x.split('~')
        b.append(x)
        x=input()

def checkouts_input(c):
    x=input()
    while x!='EndOfInput':
        x=x.split('~')
        c.append(x)
        x=input()

def output():
    global books,borrower,checkout
    date=[]
    uname=[]
    name=[]
    Anum=[]
    title=[]
    for i in range(0,len(checkout)):
    date.append(checkout[i][2])

for i in range(0,len(checkout)):
    uname.append(checkout[i][0])

for i in range(0,len(uname)):
    for j in range(0,len(borrower)):
        if(uname[i] == borrower[j][0]):
            name.append(borrower[j][1])

for i in range(0,len(checkout)):
    Anum.append(checkout[i][1])

for i in range(0,len(Anum)):
    for j in range(0,len(books)):
        if(Anum[i] == books[j][0]):
            title.append(books[j][1])

final=[]
for i in range(0,len(checkout)):
    final.append(date[i]+'~'+name[i]+'~'+Anum[i]+'~'+title[i])
final.sort()
for i in range(0,len(final)):
    print(final[i])


books=[]
borrower=[]
checkout=[]
x=input()
x=input()
while x!='Borrowers':
    x=x.split('~')
    books.append(x)
    x=input()
borrowers_input(borrower)
borrower.sort()
checkouts_input(checkout)
output()

答案 1 :(得分:0)

尝试

def borrowers_input(b):
   x=input()
   while x!='Checkouts':
        x=x.split('~')
        b.append(x)
        x=input()

def checkouts_input(c):
    x=input()
    while x!='EndOfInput':
        x=x.split('~')
        c.append(x)
        x=input()

def output():
    global books,borrower,checkout
    date=[]
    uname=[]
    name=[]
    Anum=[]
    title=[]
    for i in range(0,len(checkout)):
        date.append(checkout[i][2])

    for i in range(0,len(checkout)):
        uname.append(checkout[i][0])

    for i in range(0,len(uname)):
        for j in range(0,len(borrower)):
            if(uname[i] == borrower[j][0]):
                name.append(borrower[j][1])

    for i in range(0,len(checkout)):
        Anum.append(checkout[i][1])

    for i in range(0,len(Anum)):
        for j in range(0,len(books)):
            if(Anum[i] == books[j][0]):
                title.append(books[j][1])

    final=[]
    for i in range(0,len(checkout)):
        final.append(date[i]+'~'+name[i]+'~'+Anum[i]+'~'+title[i])
    final.sort()
    for i in range(0,len(final)):
        print(final[i])


books=[]
borrower=[]
checkout=[]
x=input()
x=input()
while x!='Borrowers':
    x=x.split('~')
    books.append(x)
    x=input()
borrowers_input(borrower)
borrower.sort()
checkouts_input(checkout)
output()