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 Limit

Someone asked an AI for a function long_walks(walks, limit) that counts the walks of at least limit minutes; for example, long_walks([30, 45, 20, 60], 30) gives 3. The answer they got gives 3 for that example. Here it's called with a limit of 50, and it prints Walks: 3 again. Check that by hand: how many of the walks are at least 50 minutes? Then click the line with the mistake.

1def long_walks(walks, limit):
2    count = 0
3    for minutes in walks:
4        if minutes >= 30:
5            count += 1
6    return count
7
8print("Walks:", long_walks([30, 45, 20, 60], 50))
9
Back

5/6

  1. 1. It Runs, and It's Wrong
  2. 2. Quiz: At Least 30 Minutes
  3. 3. The Cases Nobody Asked About
  4. 4. A Result That Looks Right
  5. 5. Quiz: The Limit
  6. 6. Summary
Next

Try it yourself

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