CSC111 Lab 2 2014

From dftwiki3
Revision as of 15:18, 4 February 2014 by Thiebaut (talk | contribs) (Adding Code)
Jump to: navigation, search

--D. Thiebaut (talk) 14:06, 4 February 2014 (EST)



Teller Machine Program

ATM.jpg


This section has to do with a program that takes some integer (without a decimal part) amount of dollars and figures out how to break it down into the least number of 20-, 10-, 5-, and 1-bills.

An Example


Pseudo-Code


On a piece of paper, figure out an algorithm for taking the amount of money to withdraw from the ATM, or teller machine, and compute the number of different bills. Write it down in pseudocode, i.e. a mixture of English and Python.

  • You need to start with some amount
  • You compute first the number of $20 bills,
  • then the number of $10 bills,
  • ...
  • down to the number of $1 bills.


Comments


  • Use Idle and open a new window.
  • In a new window, put down your pseudo code in several lines and put a #-sign in front of each line, so that they become Python comments.
  • Try to run the program and verify that no errors are detected. There shouldn't be any Python code in your program, only comments. Idle will be able to tell you if it sees anything else that is not a comment!


Adding Code


  • Now that you have the structure for your program, add enough Python code to make your code display
    • The total amount
    • The number of $20-bills


  • When you get the right number output, add some more python to get the program to print the amount of $10-bills.


  • Finish up the program


  • Verify that your program works. Below is a typical output you should try to emulate:


Amount to withdraw =  97

Please lift keyboard and find: 
4 $20-bill(s)
1 $10-bill(s)
1 $5-bill(s)
2 $1-bill(s)


Using Constants

  • You probably have statements like these in your program