Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Would anyone please debug this python code? def main(): # Get the number of vide

ID: 3889075 • Letter: W

Question

Would anyone please debug this python code?

def main():

# Get the number of videos in the project.

num_videos = int(input('How many videos are in the project? ')

# Open the file to hold the running times.

video_file = open('video_times.txt', 'w')

# Get each video's running time and write it to the file.

print('Enter the running times for each video.')

  

for count in range(1, num_vidoes + 1):

run_time = float(input('Video #' + str(count) + ': '))

video_file.write(str(run_time) + ' ')

# Close the file.

video_file.close()

print('The times have been saved to video_times.txt.)

# Call the main function

main()

Explanation / Answer

def main():
    # Get the number of videos in the project.

    nv = int(raw_input('Enter number of videos : '))

    # Open the file to hold the running times.

    video_file = open('video_times.txt', 'w')

    # Get each video's running time and write it to the file.

    print ('Enter the running times for each video.')

    lst = range(1,nv+1) // broke two steps into one
    for count in lst:
        run_time = float(raw_input('Video #' + str(count) + ': '))
        video_file.write(str(run_time) + ' ') // keeping this outside the for loop will only print the last line


    # Close the file

    video_file.close()

    print('The times have been saved to video_times.txt.')

    # Call the main function

main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote