python code

0 comments

Project 3 Draft: ATM

Introduction

Your task for this project is to create a very simple ATM. The project is broken into three sections:

  1. Collect customer input
  2. Calculate the ending balance
  3. Display the results to the customer

Your final output should look like this:

Beginning Balance: 500.50
Deposit Amount: 200
Withdrawal Amount: 100

Collect Customer Input

If the action is Balance ‘B’, use a print balance function to return and print an account balance. You will need to write a function called printbalance.

  1. The opening balance has been assigned to a variable called account_balance equal to $500.25. Notice the use of the ‘float’ method in order to ensure that ‘account_balance’ is a float value.
  2. Request the action to be taken on the account.
  3. a. Create a prompt for the user to input the account action. There are three possible actions:

    Code Action Function
    D Deposit deposit_amount
    W Withdrawal withdrawal_amount
    B Account Balance account_balance
  4. Write a print balance function that returns the account balance.
  5. Create the action for selection ‘B’, Account Balance, to call the print balance function then print the account balance once the value is returned from the function.
  6. Test your code.
  7. Create a function to print the account_balance, print the account actions and create the action for outputting the account balance outputting.

    Input Information

    The following data will be used as input in the test:

    <code>userchoice = input (<span class="hljs-string">"What would you like to do?"</span>)
    userchoice = <span class="hljs-string">'B'</span>
    </code>

    Output Information

    <code>Your current balance:
    <span class="hljs-number">500.25</span></code>

Calculate the Balance – Deposit

If the action is Deposit ‘D’, use a deposit function to add funds to the account

  1. Write a function called `deposit`.
  2. Request from the user the amount to be deposited. This value should be stored in a variable called `deposit_amount`. Use both the `input` and `float` methods in order to ensure the `deposit_amount` is a float value.
  3. Calculate a new account balance.
  4. The calculation for depositing funds into the account is `account_balance = account_balance + deposit_amount`.
  5. Print the new account balance.
  6. Deposit Input

    <code>userchoice = input (<span class="hljs-string">"What would you like to do?n"</span>)
    userchoice = <span class="hljs-string">'B'</span>
    deposit_amount = <span class="hljs-number">200</span>
    </code>

    Deposit Output

    <code>What would you like to do?
    How much would you like to deposit today?
    Deposit was $200, current balance is $700.25
    
    
    </code>

    Calculate the Balance – Withdrawal

    If the action is Withdrawal ‘W’, use the withdrawal function to remove funds from the account

    1. You will need to define a function called withdrawal.
    2. Request from the user the amount to be withdrawn. This value should be stored in a variable called withdrawal_amount. Use both the input and float methods in order to ensure the withdrawal_amount is a float value
    3. Ensure the withdrawal_amount is not greater than the account_balance.
      1. If the withdrawal_amount is greater than the `account_balance`, print the following message:withdrawal_amount is greater than your account balance of account_balanceEnsure you display the withdrawal amount and the account balance with the ‘$’ and two decimal points.
    4. If the withdrawal amount is less than or equal to the account_balance then calculate a new account balance.
    5. The calculation for withdrawing funds from the account is account_balance = account_balance - withdrawal_amount
    6. Print print the following message:Withdrawal amount was withdrawal_amount, current balance is account_balance
    7. Hint – The formatter for a float value in Python is %f. With the formatter %.2f, you format the float to have 2 decimal places. For example:

      print("Account balance: $%.2f" % account_balance)

      Withdrawal Information

      Withdraw Input

      <code>userchoice = input (<span class="hljs-string">"What would you like to do?n"</span>)
      userchoice = <span class="hljs-string">'W'</span>
      withdrawal_amount = <span class="hljs-number">100</span>
      </code>

      Withdraw Output

      <code>What would you like to do?
      How much would you like to withdraw today?
      Withdrawal amount was $100, current balance is $600.25
      
      
      </code>

      ATM Summary

      Your final function in the ATM Script is the Print the Customer summary as follows:

      Final Input

      <code>userchoice = input (<span class="hljs-string">"What would you like to do?n"</span>)
      userchoice = <span class="hljs-string">'Q'</span>
      </code>

      Final Output

      <code>What would you like to do?
      Thank you for banking with us.
      
      </code>
       
      
      



      Two paragraphs on the below prompt:

      II. Reflection – 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.

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}