How can I delete the last item in a list in Python?
I’m working on a program that calculates the time taken to answer a specific question. The program quits the loop when the answer is incorrect, but I want to delete the last calculation so I can use min()
to get the correct time, excluding the incorrect entry. Here’s my code:
from time import time
q = input('What do you want to type? ')
a = ' '
record = []
while a != '':
start = time()
a = input('Type: ')
end = time()
v = end - start
record.append(v)
if a == q:
print('Time taken to type name: {:.2f}'.format(v))
else:
break
for i in record:
print('{:.2f} seconds.'.format(i))
How can I remove the last element from the record
list so that I can calculate the minimum time without including the incorrect answer? How can I achieve this using python list remove last element
?