making a lap timer which needs to prompt for lap times until the user enters a lap time of x. User input needs to be a float as it will likely contain times including decimal points. I understand that an input can only pass 1 argument but I can not think of another way to do this.
tried string formatting (obviously not going to work on a float). tried using both for and while loops.
#Enhanced laptimer w/ list
laps=[]
lapcount=0
while True:
lapcount=+1
result=float(input("Enter lap time for lap", lapcount, "(push x to end): "))
if result == x:
break
laps.append(result)
laps.sort()
print("Fastest lap was", laps[0])
print("Slowest lap was", laps[-1])
print("Average lap was", sum(laps)/len(laps))
I expect the output to look like this : Enter lap time 1 ("x" to end): 23.4 Enter lap time 2 ("x" to end): 25.1 Enter lap time 3 ("x" to end): 27.3 Enter lap time 4 ("x" to end): 22.0 Enter lap time 5 ("x" to end): x Fastest Lap Time: 22.0 Slowest Lap Time: 27.3 Average Lap Time: 24.45
Instead I get this exception: result=input("Enter lap time for lap", lapcount, ". (push x to end): ") TypeError: input expected at most 1 arguments, got 3
Use string formatting:
result = float(input("Enter lap time for lap %s (push x to end): " % lapcount))