r/learnpython • u/x_slysuccubus_x • 10d ago
I am a college student struggling with intro to programming! Help?
Program written in Python containing:
a. An empty list that will contain float values of lap speeds.
b. A loop which gets input from user on lap speeds. This loop continues until the user enters -1.
c. While the loop iterates, the application adds the lap speed to the list.
d. Upon termination of the loop, the application displays:
i. Fastest lap speed formatted with two decimal places
ii. Slowest lap speed formatted with two decimal places
iii. Average lap speed formatted with two decimal places
e. The application displays all of the laps on screen formatted with two decimal places.
def main():
lapSpeeds()
def lapSpeeds():
lapTime=[] #empty list
lapSpeed = float(input("Enter the time the lap took to complete(-1 to calculate): ")) #start loop
lapNum = 0
while lapTime != -1:
lapTime.append(lapSpeed)
lapNum += 1
lapSpeed = float(input("Enter the time the lap took to complete(-1 to calculate): ")) #append loop
print(lapNum, ".) ", lapTime " mph")
else:
fastLap = (max.lapTime)
slowLap = (min,lapTime)
avgLap = lapTotal/lapNum
print("Fastest Lap: ", format(fastLap, ".2f") "mph")
print("Slowest Lap: ", format(slowLap, ".2f") "mph")
print("Average Lap: ", format(avgLap, ".2f") "mph")
main()This is what I get. what am I doing wrong?!
Enter the time the lap took to complete(-1 to calculate): 48949
Enter the time the lap took to complete(-1 to calculate): -1
1 .) [48949.0]
Enter the time the lap took to complete(-1 to calculate): 457
2 .) [48949.0, -1.0]
Enter the time the lap took to complete(-1 to calculate):
Also, the output should look like this
EX:
**************************************************************************************
Enter the time the lap took to complete(-1 to calculate): 199.56
Enter the time the lap took to complete(-1 to calculate): 200.01
Enter the time the lap took to complete(-1 to calculate): 200.98
Enter the time the lap took to complete(-1 to calculate): 199.94
Enter the time the lap took to complete(-1 to calculate): 200.64
Enter the time the lap took to complete(-1 to calculate): -1
Fastest Lap: 200.98 mph
Slowest Lap: 199.56 mph
Average Lap: 200.23 mph
Lap Speeds
1.) 199.56 mph
2.) 200.01 mph
3.) 200.98 mph
4.) 199.94 mph
5.) 200.64 mph
******************************************************************************************