-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTimes.py
37 lines (35 loc) · 1.06 KB
/
Times.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""This script allows you to records multiple string values and the amount of times they've been entered.
It logs the strings and amount values in a text file called 'times.txt'"""
def addTime(time,t):
if(time=="RESET"):
return []
for n in range(len(t)):
if(t[n][0]==time):
t[n][1]+=1
return t
t.append([time,1])
return t
times=[]
wrd=""
with open("times.txt",'r+') as f:
for l in f.read():
if(l!="~" and l!="\n"):
wrd=wrd+l
elif(l=="~"):
num,amount=wrd.split("-")
times.append([num,int(amount)])
wrd=""
print("Add time? Y/N")
addMore=input()
while(addMore=="Y"):
times=addTime(input(),times)
print("Add more time? Y/N")
addMore=input()
with open("times.txt",'w') as f:
for num,amount in times:
f.write(num+"-"+str(amount)+"~\n")
print(times)
seconds=0#COMMENT OUT THIS PART IF YOU AREN'T RECORDING TIMES
for num,amount in times:
seconds+=((int(num[-2:])+(int(num[:-3])*60))*amount)
print("Total time:",seconds,"seconds or",divmod(seconds,60)[0],"minutes and",divmod(seconds,60)[1],"seconds.")#COMMENT OUT THIS PART IF YOU AREN'T RECORDING TIMES