1. The program should initialize with two variables, one called balance that starts with a float of 0, and one called otherBalance that also starts with a float of 0. [5% marks] 2. Create the following functions: i) getBalance() [5% marks] ■ This should only return the value of balance ii) getOtherBalance() [5% marks] ■ This should only return the value of otherBalance iii) printBalances() [10% marks] ■ This should call getBalance() and getOtherBalance(), and print the returned values out with a dollar symbol and two decimal places (i.e., $10.99) (Hint: you can use format() function here to print the returned values) iv) deposit(money) [15% marks]
#Question 1
balance=0.0
otherBalance=0.0
#Question2
def getBalance():
return balance
def getOtherBalance():
return otherBalance
def printBalance():
bala=getBalance()
bal=round(bala,2)
other=getOtherBalance()
other=round(other,2)
print("Balance $",bal, "and otherBalance $", other)
def deposit(amount):
balance=getBalance()
balance+=amount
print("Balance after deposit is $",balance)
return(balance)
getBalance()
getOtherBalance()
printBalance()
deposit(100)
Comments
Leave a comment