Python
Function Name:
sign_count
Parameters: a list of integers
Returns: an integer
Description: Speed signs should be posted every mile on a given street. You are given a list of 0s & 1s, where each number represents a quarter of a mile. Thus, every 4 zeroes requires a speed sign. However, a 1 indicates an intersection, and each intersection is automatically required to have a speed limit sign. A sign for each mile proceeds as usual after the intersection.
Your goal is to count the number of signs required for a given stretch of road, that is represented by a list of 0’s & 1’s.
Example Call: sign_count([1,1,1]) Expected Result: 3
Example Call: sign_count([0,0,0]) Expected Result: 0
Example Call: sign_count([0,0,0,0]) Expected Result: 1
Example Call: sign_count([0,0,0,0,0,0,0,0]) Expected Result: 2
Example Call: sign_count([0,1,1,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,0]) Expected Result: 7
def sign_count(lst): count, zero_count = 0, 0 for num in lst: if num == 1: count += 1 zero_count = 0 else: zero_count += 1 if zero_count == 4: zero_count = 0 count += 1 return count print(sign_count([1, 1, 1])) print(sign_count([0, 0, 0])) print(sign_count([0, 0, 0, 0])) print(sign_count([0, 0, 0, 0, 0, 0, 0, 0])) print(sign_count([0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]))
Python Function Name: sign_count Parameters: a list of integers Returns: an integer Description: Speed signs should...
Python Function Name: unscramble Parameters: a string Returns: a string Description: Write a function, unscramble, that takes an input string, and returns a the unscrambled version of the argument. To unscramble the string: When the string has an odd number of characters, middle character is the first character in the unscrambled result Pairs of remaining characters are added to the result, proceeding left to right from inner-most to outer-most characters. Example Call: unscramble('3cis1') Expected result: ics31 Example Call: unscramble('ocicssol') Expected...
Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...
How can we assess whether a project is a success or a failure? This case presents two phases of a large business transformation project involving the implementation of an ERP system with the aim of creating an integrated company. The case illustrates some of the challenges associated with integration. It also presents the obstacles facing companies that undertake projects involving large information technology projects. Bombardier and Its Environment Joseph-Armand Bombardier was 15 years old when he built his first snowmobile...