【发布时间】:2020-06-02 17:16:25
【问题描述】:
numberofbands = int(input("How many bands are there in the competition? "))
print("Input each band’s name pressing enter after each one")
file = open("scores.txt","w")
for loop in range(numberofbands):
name = input("\nEnter the name of the band: ")
votes = input("Enter how many votes that band received: ")
file.write(name + "," + votes + "," + "\n")
file.close()
number_of_lines = len(open("scores.txt").readlines( ))
def removebelowthreshold():
threshold = int(input("Choose the threshold of scores to remove bands which are below"))
removebelowthreshold()
代码会将乐队的名称和乐谱写入文件。
如果乐队的分数低于用户给定的某个阈值,则它应该在文件中删除乐队的详细信息。希望你能帮忙。
提前谢谢你
【问题讨论】:
-
所以你要求我们为你写完整的逻辑?如果您尝试一下会好得多,只有当您无法成功时,您才应该发布minimal reproducible example 以供我们帮助。
-
@ShadowRanger 我可以通过 data = line.split(",") 和 if data[1] > threshold: 来查询文件。但是,我不知道如何从文件中删除这些行。
标签: python function file input