# The algorithm below (enclosed in the for loop) handles all cases (function( timeout ) {  +  I know it’s an old topic, but last exercise could be shortened to that: Learn how your comment data is processed. Code definitions. ... codingbat / python / logic-2 / make_chocolate.py / Jump to. Contribute to faayam/coding-bat-solutions development by creating an account on GitHub. All solutions were successfully tested on 18 April 2013. download the GitHub extension for Visual Studio. Pretty self explanatory, the solutions I came up with when I did the problem sets.

); def xyz_there(str): def count_hi(str): If nothing happens, download GitHub Desktop and try again. For ‘cat_dog’, would you criticize this solution: they're used to gather information about the pages you visit and how many clicks you need to accomplish a task.

In the real world you would normally use that method instead of rolling your own. Learn more. We use essential cookies to perform essential website functions, e.g. We use optional third-party analytics cookies to understand how you use GitHub.com so we can build better products. Learn more. count = 0 You’re using an in-built method, which defeats the purpose of this exercise.

Please can someone elaborate as to why the solution for xyz_there: does not give the out of range error?

Your email address will not be published. var notice = document.getElementById("cptch_time_limit_notice_59"); # leading “xyz” is counted, then I avoid writing another if statement, for i in range(len(str) – 3): Yes, the String class in Python does have a method named count. if str[i:i+2] == ‘hi’: Pretty self explanatory, the solutions I came up with when I did the problem return False, This is a better solution than the one you gave for `xyz_there`. codingbat-python-solutions / logic-1.py / Jump to Code definitions cigar_party Function date_fashion Function squirrel_play Function caught_speeding Function sorta_sum Function alarm_clock Function alarm_clock Function love6 Function in1to10 Function near_ten Function Can you please explain why the -1 would matter? notice.style.display = "block"; Rather, my question centers around the usefulness of using Python’s built-in list methods, as opposed to writing something more ‘verbose’. Is it because the last index is omitted in the range(len), so we only need to subtract 1 to get to -2? return True def xyz_there(str):

I know we are looking for the string ‘hi’, so why subtract one from the string? However, assuming such a method exists, and does what you intend it to do, you could simply write “return str.count(‘cat’) == str.count(‘dog’)”. Use Git or checkout with SVN using the web URL. if ( notice ) Please reload CAPTCHA.

they're used to gather information about the pages you visit and how many clicks you need to accomplish a task.