CS110 Introduction to Computing
Fall 2006
Lab Assignment#3
In this assignment you are required to solve two problems (in two separate Python programs).
Assignment:
Problem#1: Write a Python program to simulate an ATM machine. This ATM gives out bills in 20s, 10, 5s, and 1s. Ask the user to enter a dollar amount, calculate how many 20s, 10s, 5s, and 1s the amount will come out as. The ATM will always give out as many 20s as possible, then move on to 10s, and so on. Here is a sample interaction with the program (red is program output(s), blue is user input):
Enter an amount to withdraw (only whole dollar amounts, please) : $853
Your change will be issues in 42 twenties, 1 tens, 0 fives, and 3 ones.
Your program will need to do the computation using the integer divide (/) and modulus (%) operations.
Demonstrate the output of your program for $0, $9, $298, and $999.
Problem#2: Do programming Exercise 17 in Chapter 3 of Zelle (page 74-75). Here is a sample interaction with the resulting program:
This program approximates square roots of a number using Newton's method.
Enter your number: 100
How many iterations should I use? 4
Approximate square root is 10.0304952039
Difference from math.sqrt is -0.0304952038898
Show at least 3 sample runs of your program on values 10, 123456, 982081 for 10, 20, 50 iterations respectively.
What you will need to do
Notes:
Add the following line to all your Python programs:
# File: <place name of your program file here> # Date: <date created> # Created by: <your name> # Assignment: <place assignment number here>