如何从无限列表中继续呼叫

2024-09-27 21:34:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在制作一个从名为readerlist的列表中调用人员的图表。我怎么称呼第一第二第三。。。从无限列表中删除,而无需手动全部写出



def isNumber(s):
    try:
        int(s)
        return True
    except ValueError:
        return False




readerlist = []
booklist = []




print ("welcome to the book club system".upper())
print()

while True :
    print ("\n------------------------------------")
    print ("|".ljust(12) + "OPTIONS MENU".ljust(23) + "|")
    print ("|".ljust(35) + "|")
    print ("| 1: Modify book total".ljust(35) + "|")
    print ("| 2: Displays people and books out".ljust(35) + "|")
    print ("| 3: Quit".ljust(35) + "|")
    print ("------------------------------------")
    
   
    while True :
        choice = input("\nEnter your selection: ")
        if choice == "1" or choice == "2" or choice =="3":
            break
        print ("Invalid option")

    #3 - quit
    if choice == "3" :
        break
    
    #2 - display totals so far
    elif choice == "2" :
        print ("\n\n")
        
        print ("".ljust(10) + "BOOKS READ".center(30)) 
        print ("NAME".ljust(15) + "BOOKS".ljust(15))
        print (readerlist[0].ljust(15) + str(booklist[0]).ljust(15))
        print (readerlist[1].ljust(15) + str(booklist[1]).ljust(15))
        print (readerlist[2].ljust(15) + str(booklist[2]).ljust(15))
        print (readerlist[3].ljust(15) + str(booklist[3]).ljust(15))
        print (readerlist[4].ljust(15) + str(booklist[4]).ljust(15))
        
    #1 - enter a new user, or update an existing user's total
    elif choice == "1":
        while True:
            name = input("Enter your name: ")
            if name != "<Empty>":
                readerlist.append(name)
                break
                
        while True:
            books = (input("Enter number of books read: "))
            if isNumber (books):
                books = int(books)
                break
            else:
                print("Invalid number")
               

        
print ("")
print ("Thank you for using the Library program")
input ("<Hit ENTER to exit>")


Tags: ornametrue列表inputifbooksprint
1条回答
网友
1楼 · 发布于 2024-09-27 21:34:24

也许这就是你想要的:

    elif choice == "2" :
        print ("\n\n")
 
    print ("".ljust(10) + "BOOKS READ".center(30)) 
    print ("NAME".ljust(15) + "BOOKS".ljust(15))
    for i in readerlist:
        print(readerlist[i].ljust(15) + str(booklist[i]).ljust(15))

相关问题 更多 >

    热门问题