我已经使用python创建了文件,我需要比较它。我如何使用python比较这两个文件?比较我创建的python文件
def td():
choice = input("which trainning event would you like to access?
\n1.swimming
\n2.cycling
\n3.running\nplease type in the number before the event of which you want to choose\n")
if choice == "1":
Swimming_file= open("Swimming_file.txt", "w")
totaldistance = input("what was the total distance you swam in meters?")
totaltime = input("how long did you swim for in minutes?")
speed = totaldistance/totaltime
print ("on average you where running at a speed of", speed, "mps")
total = (totaldistance, totaltime, speed)
Swimming_file.write(str(total))
Swimming_file.close()
elif choice == "3":
Running_file= open("Running_file.txt", "w")
totaldistanceR = int(input("what was the total distance you ran in KM?"))
totaltimeR = int(input("how long did you run for in minutes?"))
totaltimeR1 = 60/totaltimeR
speedR1 = totaldistanceR/totaltimeR1
print ("The records have been saved")
print ("on average you where running at a speed of", speedR1, "KMph")
totalR = (totaldistanceR, totaltimeR, speedR1)
Running_file.write(str(totalR))
Running_file.close()
elif choice == "2":
Cycling_file= open("Cycling_file.txt", "w")
totaldistancec = int(input("what was the total distance you ran in KM?"))
totaltimec = int(input("how long did you run for in minutes?"))
speedc = totaldistancec/totaltimec
print ("on average you where running at a speed of", speedc, "KMph")
totalc = (totaldistancec, totaltimec, speedc)
Cycling_file.write(str(totalc))
Cycling_file.close()
创建的文件包含以用户名命名的运行时间。我需要比较文件,以便用户可以看到其他用户的速度。
我一直在寻找这个解决方案的互联网,但没有任何与我的问题有关。
你能不能给你有文件数据? – jack 2014-11-05 06:27:58
我编辑了这个问题 – Kelly 2014-11-05 06:37:37