In: Computer Science
Develop a python program that will determine if a department store customer has exceeded the credit limit on a charge account. For each customer, the following facts are available: Account number, Balance at the beginning of the month, Total of all items charged by this customer this month, Total of all credits applied to this customer’s account this month and Allowed credit limit. The program should input each of the facts, calculate the new balance (=beginning balance + charges – credits), and determine if the new balance exceeds the customer’s credit limit. For those customers who credit limit is exceeded, the program should display the customer’s account number, credit limit, new balance and the message “Credit limit exceeded”. Here is a sample input/output dialogue: Enter account number (-1 to end): 100 Enter beginning balance: 5394.78 Enter total charges: 1000.00 Enter total credits: 500.00 Enter credit limit: 5500.00 Account: 100 Credit limit: 5500.00 Balance: 5894.78 Credit Limit Exceeded. Enter account number (-1 to end): 200 Enter beginning balance: 1000.00 Enter total charges: 123.45 Enter total credits: 321.00 Enter credit limit: 1500.00 Enter account number (-1 to end): -1 # -1 is terminating condition
Please find below well-commented code in Python.
Note: Make sure to use correct indentation while coding in python. Also, the use of spaces is recommended over tabs.
Code text:
while(True): accountNumber = int(input("Enter account number(-1 to end): ")) #Get account number from user if(accountNumber == -1): #Check if account number is -1 break #if yes end the program beginningBalance = float(input("Enter beginning balance: ")) #get beginning balance totalCharges = float(input("Enter total charges: ")) #get charges totalCredit = float(input("Enter total credits: ")) #get credits creditLimit = float(input("Enter credit limit: ")) #get credit limit newBalance = beginningBalance + totalCharges - totalCredit #calculate new balance according to the formula if(newBalance > creditLimit): #check if new balance exceeds credit limti or not print("Account: " + str(accountNumber)) print("Credit limit: " + str(creditLimit)) print("Balance: " + str(newBalance)) print("Credit Limit Exceeded") |
Code image:
Output: