Have a Python program ask the user to enter the number of times they ran around a track (laps). Next, use a 'for' or a 'while' loop to have the user enter the time it took to run each lap. When the loop is finished, display the total number of laps they ran and the total time it took them to run all laps. Label the time numbers in seconds. (Do not use 'if' or 'else' please, I have not learned about that yet so I want to stay simple). Here is my current code, it isn't working because it will not return the total number of laps the user inputs and the total time for each lap. It keeps saying 'You ran 1 laps, total time spent:" whatever the last number is, not the total time. # Display the variables for lap and time spent total_lap = 0 total_time = 0 # Have the user input how many laps they ran num_lap = int(input("Input the number of laps: ")) # Create a while loop to have the user input the time spent on all laps for lap in range(1, num_lap + 1):     lap_time = float(input(f"Enter the amount of seconds spent for lap {lap}: "))      # Combine all laps total_lap += 1 # Combine lap time and total time spent total_time += lap_time lap += 1 # Show end result and have the units at the end print(f"You ran {total_lap} laps") print(f"Total time spent: {total_time} seconds{'s' * (total_time != 1)}")   What can I do to fix this code so it works properly? Thanks!

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Hello! I am independently learning about functions on my own. I am trying to challenge myself when writing Python to create this: I will write it out specifically so you know how I am basing my code,

Have a Python program ask the user to enter the number of times they ran around a track (laps). Next, use a 'for' or a 'while' loop to have the user enter the time it took to run each lap. When the loop is finished, display the total number of laps they ran and the total time it took them to run all laps. Label the time numbers in seconds. (Do not use 'if' or 'else' please, I have not learned about that yet so I want to stay simple).

Here is my current code, it isn't working because it will not return the total number of laps the user inputs and the total time for each lap. It keeps saying 'You ran 1 laps, total time spent:" whatever the last number is, not the total time.

# Display the variables for lap and time spent

total_lap = 0
total_time = 0

# Have the user input how many laps they ran

num_lap = int(input("Input the number of laps: "))

# Create a while loop to have the user input the time spent on all laps

for lap in range(1, num_lap + 1):
    lap_time = float(input(f"Enter the amount of seconds spent for lap {lap}: "))
    

# Combine all laps

total_lap += 1


# Combine lap time and total time spent

total_time += lap_time

lap += 1


# Show end result and have the units at the end


print(f"You ran {total_lap} laps")

print(f"Total time spent: {total_time} seconds{'s' * (total_time != 1)}")

 

What can I do to fix this code so it works properly? Thanks!

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Types of Loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education