Question: def count _ 0 s _ 1 s ( s ) : ' ' ' Check whether the input string s is monotonic.

def count_0s_1s(s):
'''
Check whether the input string "s" is monotonic.
'''
# TODO: Write your code to implement this function.
# (1) Test your function with input string 'abc'. It should return None.
print(count_0s_1s('abc'))
#>>> The input string must contain only 0s and 1s!
#>>> None
# (2) Test your function with input string '1'. It should return (0,1).
print(count_0s_1s('1'))
#>>>(0,1)
# (3) Test your function with an empty input string ''. It should return None.
print(count_0s_1s(''))
#>>> The input string must contain at least one 0 or 1!
#>>> None
# (4) Test your function with input string '01'. It should return (1,1).
print(count_0s_1s('01'))
#>>>(1,1)
# (5) Test your function with input string '01010001'. It should return (5,3).
print(count_0s_1s('01010001'))
#>>>(5,3)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!