Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

Quiz: The Piece Just Added

Someone built the same report in the same steps. After adding total_minutes(), they ran the program and checked both lines by hand: Walks: 5 and Time: 190 min were right. Then they pasted week_total() from an answer, added its line to print_report() and ran the program again:

Walks: 5
Time: 190 min
Total: 190

The walks cost 48. Click the line with the mistake.

1def walk_price(minutes):
2    half_hours = minutes // 30
3    if minutes % 30 > 0:
4        half_hours = half_hours + 1
5    return half_hours * 6
6
7def total_minutes(walks):
8    total = 0
9    for minutes in walks:
10        total = total + minutes
11    return total
12
13def week_total(walks):
14    total = 0
15    for minutes in walks:
16        total = total + minutes
17    return total
18
19def print_report(walks):
20    print("Walks:", len(walks))
21    print("Time:", total_minutes(walks), "min")
22    print("Total:", week_total(walks))
23
24walks = [30, 45, 20, 60, 35]
25print_report(walks)
Back

3/7

  1. 1. A Plan Before Code
  2. 2. One Piece at a Time
  3. 3. Quiz: The Piece Just Added
  4. 4. Leave the Rest as It Is
  5. 5. A New Chat
  6. 6. Quiz: A Long Chat
  7. 7. Summary
Next

Try it yourself

Do this exercise right here in your browser. No account needed.