enumerate
可以快速索引列表
qiang_jin_jiu = ["君不见\n", "黄河之水天上来\n", "奔流到海不复回\n", "君不见,\n", "高堂明镜悲白发\n", "朝如青丝暮成雪\n", "人生得意须尽欢\n", "莫使金樽空对月\n", "天生我才必有用\n", "千金散尽复还来\n", "烹羊宰牛且为乐\n", "岑夫子\n", "丹丘生\n", "将进酒\n", "杯莫停\n", "与君歌一曲\n", "请君为我倾耳听\n", "钟鼓馔玉不足贵\n", "但愿长醉不愿醒\n", "古来圣贤皆寂寞\n", "惟有饮者留其名\n", "陈王昔时宴平乐\n", "斗酒十千恣欢虐\n", "主人何为言少钱\n", "径须沽取对君酌\n", "五花马,\n", "千金裘,\n", "忽而唤出换美酒,\n", "与尔同销万古愁\n"]line_sum = Nonefor index, line in enumerate(qiang_jin_jiu): print(index+1, line) line_sum = indexprint("将进酒共有%d句"%(line_sum+1))def printjiu(num): print("*"*30) print(qiang_jin_jiu[num-1]) print("*"*30)def main(): num = int(input("请输入需要打印的行号:")) printjiu(num)if __name__ == '__main__': main()复制代码