Question

Python Function Name: sign_count Parameters: a list of integers Returns: an integer Description: Speed signs should...

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1
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]))

30127

Add a comment
Know the answer?
Add Answer to:
Python Function Name: sign_count Parameters: a list of integers Returns: an integer Description: Speed signs should...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please read the article and answer about questions. You and the Law Business and law are...

    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...

    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...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT