[Tutor] Help Writing a Bill Calculating Program

bhaaluu bhaaluu at gmail.com
Fri Mar 28 12:32:04 CET 2008

On Fri, Mar 28, 2008 at 12:50 AM, Amin Han <amints7 at gmail.com> wrote:
> Hi, I'm currently a novice at Python, and I need help creating the
>  following program...
>  # Write a program that asks the user to enter a package number and the
>  total number of hours spent online that month (you may assume that the
>  user will enter an integer number of hours). Using the information
>  below, calculate and print the user's bill for that month.

First of all, carefully read the problem that you have been given.
Most computer programs solve a problem. At a minimum, a program
may ask for INPUT, then do a COMPUTATION of some sort, and finally
OUTPUT an answer or solution. After you've read the problem, get a
pencil and a piece of paper and write down everything you've learned
by reading the problem. At a  minimum, you should write down what
the INPUT is, what needs to be COMPUTED, and what the output is.
Things called variables hold input values, and be used in COMPUTATIONS,
and also used to provide output. It is usually helpful to have meaningful
variable names. At this point, you should have enough information to
write a simple program using pseudocode. Now work through the
pseudocode and desk-check it to see if it will do what you want it to do.
Good. At this point, translating the pseudocode to Python should be
rather straightforward.

>  # Modify your program so that it first asks for the total number of
>  bills to generate. Your program should use a loop to calculate that
>  many customer bills.

In order to modify a program, you need to have a working program.
So, if you don't have a working program yet, go back and work some
more. Once you have a working program, you'll need to review what
you know about loops. Apply that knowledge, using the same steps as
before, to this problem. INPUT->COMPUTATION->OUTPUT

>  #If possible, modify your program so that it also calculates and
>  prints what the user would have spent if he had one of the other two
>  packages. If the user would have saved money using a different
>  package, print out an appropriate message (e.g., "Package 3 would have
>  been cheaper").

Here again, use the same approach as you've already done for this problem.

>     *  Package 1: For $9.95 per month, up to 10 hours of access are
>  provided. Each additional hour costs $2.00.
>     * Package 2: For $13.95 per month, up to 20 hours of access are
>  provided. Each additional hour costs $1.00.
>     * Package 3: For 19.95 per month, a customer receives an unlimited
>  number of hours of access.

The data is very clear. What is package 1? Package 2? Package 3? Read it
and write it down until you understand each one.

>  If you could help, that would be much appreciated.  Thanks so much.

I hope this helps you get started. Once you have some Python code written,
and you still have problems, write back and ask for help with your code.
Please include your platform, Python version, and the code you're having
problems with in your post.

Happy Programming!
b h a a l u u at g m a i l dot c o m
"You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance. Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul." [Mahatma Gandhi]

More information about the Tutor mailing list