Question: 1.) Write a function hideShow that accepts two string arguments, an input string and a masking string. The masking string is a string consisting of

1.) Write a function hideShow that accepts two string arguments, an input string and a masking string. The masking string is a string consisting of 0s and 1s that has the same length as the input string. The function then returns a new string that is the same as the input string, except that it is masked. That is, in any position where the masking string contains a 0 the input character is replaced by a #, whereas if the masking string contains a 1, the character is unchanged.

All of the following sample output must work in order to pass the doctest:

>>> hideShow( 'apple', '11001') 'ap##e' >>> hideShow('apple','00000') '#####' >>> hideShow('apple','11111') 'apple' >>> hideShow('abcdefghijklmnopqrstuvwxyz',13*'01') '#b#d#f#h#j#l#n#p#r#t#v#x#z' >>> hideShow( 'df###re##', '101010101' ) 'd#####e##'

2.) Write a function moreOdds that accepts one argument, a list of integers. The function then returns a bool that indicates whether the list contains(strictly) more odd numbers than even numbers.

All of the following sample output must work in order to pass the doctest:

>>> moreOdds( [2,3,4,5,7] ) True >>> moreOdds( [2,3,4] ) False >>> moreOdds( [2,3,4,5] ) False >>> moreOdds( [2,2,5,5] ) False >>> random.seed(0) >>> moreOdds( random.sample( range(100), 25) ) True >>> random.seed(20) >>> moreOdds( random.sample( range(100), 95) ) True >>> random.seed(22) >>> moreOdds( random.sample( range(100), 95) ) False

3.) Write a function flipSwitches that accepts one argument, a sequence of upper or lower case letters (the sequence can either be a str or a list, if you write your code correctly, it shouldnt matter). This is a sequence of switches, uppercase means to turn a switch on, and lowercase to turn a switch off. For example, A means to turn the switch A on, and a means to turn the switch A off. (Turning an on switch on again, or an off switch off again, has no effect). The function should then return the set of those switches that are still on at the end of the sequence of switches. For example, the expression flipSwitches( ['A','A','a','B'] ) returns the set {'B'} because, the switch B is turned on during the sequence, whereas the switch A is turned on twice (so still on), then turned off once, so it is off at the end. To receive full credit, your code must use a set that keeps track of the switches that are on. You can then iterate over the sequence and modify the set of switches that are on as appropriate.

All of the following sample output must work in order to pass the doctest:

>>> flipSwitches( ['A','A','a','B'] ) {'B'} >>> flipSwitches( 'ABCba') {'C'} >>> flipSwitches( 'sdfjSDSDFasjjfdjldsSDF' )=={'S', 'D', 'F'} True >>> random.seed(5) >>> flipSwitches( [random.choice('abcdefABCDEF') for i in range(100)] )=={'D', 'B', 'F', 'C'} True >>> random.seed(100) >>> flipSwitches( [random.choice('abcdefABCDEF') for i in range(10000)] )=={'D', 'E', 'A', 'F'} True >>> random.seed(0) >>> flipSwitches( [random.choice('abcdefABCDEF') for i in range(10000)] )=={'E', 'A', 'C'} True

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 Databases Questions!