CSC241 Object Oriented Programming Python Function Need help creating functions and methods. Instructions, and test file provided. Part 1 1. Write a functi

CSC241 Object Oriented Programming Python Function Need help creating functions and methods. Instructions, and test file provided. Part 1
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 ‘0’s and ‘1’s 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. See the following sample output:
>>> 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. Sample output:
>>> moreOdds(
True
>>> moreOdds(
False
>>> moreOdds(
False
>>> moreOdds(
False
[2,3,4,5,7] )
[2,3,4] )
[2,3,4,5] )
[2,2,5,5] )
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
shouldn’t 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. Sample output:
>>> flipSwitches( [‘A’,’A’,’a’,’B’] )
{‘B’}
>>> flipSwitches( ‘ABCba’)
{‘C’}
>>> flipSwitches( ‘sdfjSDSDFasjjfdjldsSDF’ )=={‘S’, ‘D’, ‘F’}
True
Part 2
1. Develop a class BankAccount with six methods:
a. __init__ – constructor, is able to construct a bank account with a given balance, or, if
no balance is specified the balance defaults to 0. (see runs below)
b. __repr__ – converts BankAccount to a str for display, see runs below.
c. set which takes a numeric amount as a parameter and sets the account balance to that
parameter
d. withdraw – which takes a numeric amount as a parameter and withdraws the amount
specified by the parameter from the balance on the account
e. deposit – which takes a numeric amount as a parameter and deposits the amount
specified by the parameter from the balance on the account
f. balance – which takes no parameters and returns the current balance on the account
# constructor/repr
>>> b = BankAccount(100)
>>> b
BankAccount(100)
>>> b = BankAccount()
>>> b
BankAccount(0)
>>> [b] # check that str is returned, not printed
[BankAccount(0)]
>>> b.deposit(50.25)
>>> b
BankAccount(50.25)
>>> b.withdraw(17.50)
>>> b
BankAccount(32.75)
>>> b.balance()
32.75
>>> b.balance()==32.75 # check balance is returned, not
printed
True
2. Write a function processAccount() that takes one argument, the name of a file The
first line of the file is a number, which indicates the initial balance for a bank account.
The remaining lines consist of a single character followed by a space followed by a
number. The character will be one of ‘d’, ‘D’, ‘w’, or ‘W’, indicating that the amount that
follows is either a withdrawal (‘w’ or ‘W’) or a deposit (‘d’ or ‘D’). The function will create
a new BankAccount object and then process each line of the file by calling the
appropriate method of the BankAccount object. As it processes each line, it will print
the information about the transaction being processed. The first line will be a call to
the set() method and the remaining lines will be calls either to the deposit()
or withdraw() method. Once the file has been processed, the function will return
the BankAccount object.
>>> processAccount(‘acct1.txt’)
BankAccount(605.5500000000001)
>>> b = processAccount(‘acct1.txt’)
>>> b
BankAccount(605.5500000000001)
>>> b.balance()
605.5500000000001
>>>
>>> b = processAccount(‘acct2.txt’)
>>> b
BankAccount(46.94)
>>> b.balance()
46.94
>>>
>>> b = processAccount(‘acct3.txt’)
>>> b
BankAccount(216.64)
>>> b.balance()
216.64
>>>
1000.00
W 50.50
W 5.25
d 100.75
w 525.15
d 85.70
50.50
d 5.89
w 3.75
D 10.19
w 15.89
345.89
d 15.75
D 100
w 245

Purchase answer to see full
attachment

"Order a similar paper and get 100% plagiarism free, professional written paper now!"

Order Now