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: Which Line Is Wrong?

Someone asked for a function time_text() that writes minutes as hours and minutes, with tests, and got this answer. When they run it, it prints:

Traceback (most recent call last):
  File "<exec>", line 7, in <module>
AssertionError: 130 minutes

Work out by hand what 130 minutes should give, then click the line with the mistake.

1def time_text(minutes):
2    hours = minutes // 60
3    rest = minutes - 60
4    return f"{hours} h {rest} min"
5
6assert time_text(75) == "1 h 15 min", "75 minutes"
7assert time_text(130) == "2 h 10 min", "130 minutes"
8print("All tests passed")
9
Back

6/7

  1. 1. An Example That Runs
  2. 2. Tests First, Then the Code
  3. 3. Check the Tests Too
  4. 4. Quiz: The Function or the Test?
  5. 5. Tests with assert
  6. 6. Quiz: Which Line Is Wrong?
  7. 7. Summary
Next

Try it yourself

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