×

Challenges

  1. Not started

  2. Not started

  3. Not started

  4. Not started

  5. Not started

  6. Not started

  7. Not started

  8. Not started

  9. Not started

Challenge 6.1

Add seconds, minutes and hours of two video clips

Challenge Level: Growing experience

Requirement:

Remix the program provided at https://scratch.mit.edu/projects/165770195/. Write a program that takes the durations of two video clips as the input (asks the user to enter the number of hours, minutes and seconds) and displays the total duration as the output. For example, for planning the length of clips in a film or songs in a playlist we might need to add the length of the first clip which is 32 minutes, 21 seconds (0:32:21) to the length of another clip which is 33 minutes and 20 seconds. Each time input (hours, minutes and seconds) are entered each on a different line. The output of your program should be 1 hour, 5 minutes and 41 seconds.

Hints
  • If total seconds (sum of the number of seconds from the first clip and the second clip) is greater than 59, increase total minutes (sum of minutes from the first clip and the second clip) by 1 and set total seconds to total seconds modulo 60.
  • If total minutes (sum of the number of minutes from the first clip and the second clip) is greater than 59, increase total hours (sum of hour from the first clip and the second clip) by 1 and set total minutes to total minutes modulo 60.
Programming Reminders
# Print a string directly
print("Hello World!")

# Print a variable
print(my_var)

Variables

# Set a variable as a string
fruit_name = "Apple"

# Set a variable as an integer 
pieces_of_fruit = 7

# Set a variable from a calculation
cost_of_fruit = pieces_of_fruit * cost_per_item

# Add one to a value
pieces_of_fruit += 1

Conditionals

# Find out the discount on fruit
if pieces_of_fruit > 100:
   print("Bulk discount applies")
elif pieces_of_fruit > 5:
   print("Discount applies")
else:
   print("No discount")

For loops

# Print numbers 0-9 - remember Python starts counting from 0 
for num in range(10):
    print(num)

While loops

# Print numbers 0-9 using a while loop and a variable
num = 0
while num < 10:
    print(num)

    # Increment the variable by one.
    # It will prevent an infinite loop!
    num += 1 

Lists

# Create a list of fruit 
fruit = ["Apple", "Banana", "Orange", "Pear"]

Functions

# Create a function which prints a greeting
def greeting(name):
    print("Hello " + name)

# Call the function
greeting("Spiderman")

Enter your code in the editor below

Your results will be displayed here

Input Expected output Received output Status
0
32
21
0
33
20
Total time: 1 hours, 5 minutes, and 41 seconds

                
Not yet run ?
3
59
59
2
13
3
Total time: 6 hours, 13 minutes, and 2 seconds

                
Not yet run ?
4
59
59
2
59
59
Total time: 7 hours, 59 minutes, and 58 seconds

                
Not yet run ?