以下是我使用的文本文件示例:
NaQua,High
ImKol,Moderate
YoTri,Moderate
RoDen,High
NaThe,Moderate
ReWes,Moderate
BrFre,High
KaDat,High
ViRil,High
TrGeo,High
出于某种原因,该程序仅适用于列表中的最后一个客户端ID。它会打印出强度等级,然后就会停在那里,好像这就是程序的结束。
pie = 'pie'
while pie == 'pie':
f=open('clientIntensity.txt')
lines=f.readlines()
print ((lines[0])[:5])
print ((lines[1])[:5])
print ((lines[2])[:5])
print ((lines[3])[:5])
print ((lines[4])[:5])
print ((lines[5])[:5])
print ((lines[6])[:5])
print ((lines[7])[:5])
print ((lines[8])[:5])
print ((lines[9])[:5])
clientid = input("Please select and input the ID of the client that you would like to record exercise times for. (case sensitive)")
with open('clientIntensity.txt') as f:
for line in f:
if clientid in line:
clientintensity = line[6:]
print ("The client you have selected has an exercise intensity of",clientintensity)
if clientintensity == 'High':
print ("The exercises for this intensitity level are, Running Swimming Aerobics Football Tennis.")
while True:
try:
Running = input("Please enter the amount of time that the client spent running.(0-120 minutes)")
except ValueError:
print ("Please enter a valid time.")
continue
else:
break
while True:
try:
Swimming = input("Please enter the amount of time that the client spent swimming.(0-120 minutes)")
except ValueError:
print ("Please enter a valid time.")
continue
else:
break
while True:
try:
Aerobics = input("Please enter the amount of time that the client spent doing aerobics.(0-120 minutes)")
except ValueError:
print ("Please enter a valid time.")
continue
else:
break
while True:
try:
Football = input("Please enter the amount of time that the client spent playing football.(0-120 minutes)")
except ValueError:
print ("Please enter a valid time.")
continue
else:
break
while True:
try:
Tennis = input("Please enter the amount of time that the client spent playing tennis.(0-120 minutes)")
except ValueError:
print ("Please enter a valid time.")
continue
else:
break
totaltime = ((Running)+(Swimming)+(Aerobics)+(Football)+(Tennis))
print (clientid,"spent a total time of",totaltime,"exercising this week.")
elif clientintensity == 'Moderate':
print ("The exercises for this intensitity level are, Walking Hiking Cleaning Skateboarding Basketball")
while True:
try:
Walking = input("Please enter the amount of time that the client spent walking.(0-120 minutes)")
except ValueError:
print ("Please enter a valid time.")
continue
else:
break
while True:
try:
Hiking = input("Please enter the amount of time that the client spent hiking.(0-120 minutes)")
except ValueError:
print ("Please enter a valid time.")
continue
else:
break
while True:
try:
Cleaning = input("Please enter the amount of time that the client spent cleaning.(0-120 minutes)")
except ValueError:
print ("Please enter a valid time.")
continue
else:
break
while True:
try:
Skateboarding = input("Please enter the amount of time that the client spent skateboarding.(0-120 minutes)")
except ValueError:
print ("Please enter a valid time.")
continue
else:
break
while True:
try:
Basketball = input("Please enter the amount of time that the client spent playing basketball.(0-120 minutes)")
except ValueError:
print ("Please enter a valid time.")
continue
else:
break
totaltime = ((Walking)+(Hiking)+(Cleaning)+(Skateboarding)+(Basketball))
print (clientid,"spent a total time of",totaltime,"exercising this week.")
again = input("Would you like to input times for another client?(Y/N")
if again == 'N':
pie = 'superpie'