最近刚开始用PTA平台学算法数据结构 正好python不太会想用python练练手 就出现了如下死都过不去的测试点 题目是这样的: 输入格式: 输入n+1行,其中前n行是n本图书的信息(书号、书名、价格),每本图书信息占一行,书号、书名、价格用空格分隔,价格之后没有空格。最后第n+1行是输入结束标志:0 0 0(空格分隔的三个0)。其中书号和书名为字符串类型,价格为浮点数类型。 输出格式: 总计n+1行,第1行是所创建的图书表中的图书个数,后n行是n本图书的信息(书号、书名、价格),每本图书信息占一行,书号、书名、价格用空格分隔。其中价格输出保留两位小数。 输入样例: 在这里给出一组输入。例如: 9787302257646 Data-Structure 35.00 9787302164340 Operating-System 50.00 9787302219972 Software-Engineer 32.00 9787302203513 Database-Principles 36.00 9787810827430 Discrete-Mathematics 36.00 9787302257800 Data-Structure 62.00 9787811234923 Compiler-Principles 62.00 9787822234110 The-C-Programming-Language 38.00 0 0 0
输出样例: 在这里给出相应的输出。例如: 8 9787302257646 Data-Structure 35.00 9787302164340 Operating-System 50.00 9787302219972 Software-Engineer 32.00 9787302203513 Database-Principles 36.00 9787810827430 Discrete-Mathematics 36.00 9787302257800 Data-Structure 62.00 9787811234923 Compiler-Principles 62.00 9787822234110 The-C-Programming-Language 38.00
写的代码: count=0 book_list=[] book_id="" book_name="" book_price="" while True: book_id,book_name,book_price=input().split(" “) if book_id==“0” and book_name==“0” and book_price==“0”: break else: count+=1 book_dict = [int(book_id),book_name,float(book_price)] book_list.append(book_dict) print(count) for i in book_list: for j in i: if type(j)==float: print(”%.2f"%j) continue print(j,end=" ")