I need the following code commented and addressed: Specifically, your script sho
ID: 3709380 • Letter: I
Question
I need the following code commented and addressed: Specifically, your script should address the following critical elements:
I. In Your Script (Annotated Text File) Refer to the directions in the module in Codio for how to export out and comment your completed script. A. Identify examples of custom functions in your script using comments in your code. B. Identify examples of input (parameters) that are utilized within the function(s) in your script using comments in your code. C. Identify examples of functions that return the correct output in your script using comments in your code.
Applying Your Experience Making mistakes when you learn to write code is common. It is part of learning. What is important is developing the skill of learning how to understand your errors and then fix them (debugging). For this part of your final project, you will respond to the following: A. Reflecting on your experience with this activity, explain the importance of knowing how and when to use and modify custom functions, inputs (parameters) within functions, and functions to return the correct output. Support your response with examples from the activity of the types of errors and your method for fixing them. Thanks
import sys
# account balance
account_balance = float(500.25)
#PPrint the balance
def printbalance():
print("Your current balance : %2f" % account_balance)
#the function for deposit
def deposit():
deposit_amount = float(input("Enter amount to deposit : "))
balance = account_balance + deposit_amount
print("Deposit was $%2f, current balance is $%2f" %(deposit_amount,balance))
#function for withdraw
def withdraw():
withdraw_amount = float(input("Enter amount to withdraw"))
if(withdraw_amount > account_balance):
print("$%2f is greater than account balance $%2f " %(withdraw_amount,account_balance))
else:
balance = account_balance - withdraw_amount
print("$%2f was withdrawn, current balance is $%2f" % (withdraw_amount, balance))
# User Input goes here, use if/else conditional statement to call function based on user input
userchoice = input("What would you like to do? ")
if (userchoice == 'D'):
deposit()
elif userchoice == 'W':
withdraw()
elif userchoice == 'B':
printbalance()
else:
sys.exit()
Explanation / Answer
import sys # importing the sys library
# account balance
account_balance = float(500.25)
#PPrint the balance
# This is a custom function, it returns the current balance upto 2 decimal places
def printbalance():
print("Your current balance : %2f" % account_balance)
#the function for deposit
#This is a custom function
def deposit():
deposit_amount = float(input("Enter amount to deposit : ")) # takes in input for deposit amount
balance = account_balance + deposit_amount #calculates balance
print("Deposit was $%2f, current balance is $%2f" %(deposit_am ount,balance)) # prints out the balance
#function for withdraw
#this is a custom function
def withdraw():
withdraw_amount = float(input("Enter amount to withdraw")) # takes in the withdraw amount
if(withdraw_amount > account_balance): #checks whether the amount is more than balance or not
print("$%2f is greater than account balance $%2f " %(withdraw_amount,account_balance)) #if yes then print wd amount greater than balance
else:
balance = account_balance - withdraw_amount
print("$%2f was withdrawn, current balance is $%2f" % (withdraw_amount, balance))
# User Input goes here, use if/else conditional statement to call function based on user input
userchoice = input("What would you like to do? ")
if (userchoice == 'D'):
# here deposit function is called
deposit()
elif userchoice == 'W':
# here withdraw function is called
withdraw()
elif userchoice == 'B':
# here printbalance function is called
printbalance()
else:
# it ends the program execution
sys.exit()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.