Due Date: midnight, Friday, 23 November.
This assignment focuses on nested loops and indefinite loops from Chapter 8.
Submit the following programs via Blackboard:
Write a program that asks the user to guess a secret number. If they guess too high, you
should print out a message saying that and let them guess again. If they guess too low, you
should print out a message saying that and them them guess again. When they guess correctly,
you should thank them for playing, and the program ends.
Write a program that asks the user to enter a number between 1900 and 2012. If they
enter a number out of range, print a message that the number is out of range and prompt
them again for a number between 1900 and 2012. When the user enters a number in range, print
the number to the screen and end the program.
Write a program that asks the user to enter an integer (for example, 12345678).
The program sums the digits of the integer (in this example it gets 36). It then sums the digits
of that integer (in the example, it gets 9). It keeps going until it is down to a one-digit number,
which it prints.
Write a program that asks the users to enter a sequence of amounts to credit or debit to
their account. Your program should continue to process their amounts as long as their balance
is positive. If at any point they have a negative balance, print a message and end the program.
If you are able to process all the amounts, print the final balance to the screen before
ending the program. You may assume that their beginning balance is $1000.
One sample run of the program:
Please enter the amounts to credit/debit from your account, separated by commas: -500,100.01,-1000,333.33,85.02,-200
Beginning Balance: $1000.00
Balance: $ 500.00
Balance: $ 600.01
Your balance has dropped below 0! Please contact the bank immediately!
Another sample run of the program:
Please enter the amounts to credit/debit from your account, separated by commas: 5.00,123.01,-600,7.89,-99.99
Beginning Balance: $1000.00
Balance: $ 1128.01
Balance: $ 528.01
Balance: $ 535.90
Balance: $ 435.91
Your final balance is: $ 435.91
Write a program that reads in a text file, infile.txt, and prints out all the
lines in the file to the screen until it encounters an empty line. Once it finds an empty line,
the program stops.
For more information on using Blackboard, see the first lab
Two of the five submitted programs will be chosen at random for grading.
Assignments must be submitted by midnight on the date due.
Every program should begin with a comment that includes your name and a brief description.
No credit will be given for a late assignment.
Extra credit will be awarded for graded programs that are submitted early. If a graded
program is submitted more than 12 hours early (before Friday noon), 1 extra credit point will be awarded. For
graded programs submitted more than 24 hours early (Thursday or earlier), 2 extra credit points will be
You MUST attach your program as a file, you may also cut and paste your program into the submission box.
The name of the file that you submit should begin with your last name (for example: yourlastnamePS2_2.py).
Your file MUST have a file type of .py
Your program should contain a function definition for main(), and it should invoke main() at the end of the
While working on this assignment you have access to help in class (if your question might be
of general interest), at the Math Lab, during office hours, and using the discussion forum for this
problem set on Blackboard. Please take advantage of all of these resources.