To take part in discussions on talkSFU, please apply for membership (SFU email id required).

cmpt 165 assignment

edited August 2010 in General
for anyone whose taken the course:

Marking Scheme - Purchase History
5. Now, edit your navigation once again such that it is now possible to view a userʼs order
or purchase history. Once again, it is up to you where you like to place this item (hint:
very much related to the order form). The purchase history should contain a form with
three items:
a) Textbox for the customerʼs first and last name.
b) A find button.
6. Next, write a python script that outputs all the individual purchases (and a grand total)
made by the customer. To do this, you will have to save all your customersʼ names and
purchases into a text file called customers.data that is accessible to different programs
that need it. Fortunately, you will not have to do this yourself; the provided module
customerlib will do this for you. You should download the source code for the module
and put it in the same directory as your “purchase history” program. The module defines
these functions:
- Each time a new purchase is made you should include the function call:
customerlib.write(firstname,lastname,amount)
where firstname and lastname are the strings representing the customerʼs name,
and amount is the total for that particular purchase.
-
When you would like to find a customerʼs purchase records, you should use the
function call:
history = customerlib.find(firstname,lastname)
this will return a list of strings representing the past purchases for this particular
customer.
Product1
3×$4.50
$13.50
Product2
4×$5.00
$20.00
SUBTOTAL
$33.50
In general, the purchase history could look something like this:
Firstname Lastname, you have a purchase history of:
• $34.65
• $56.45
• $12.53
The total of all your purchases is $103.63
We will be playing around with this module in Lab 10.
7. In order to use the module, you must save the customerlib.py file in the same directory
as your python script, to access the module, you must type in:
import customerlib
this tells your program that you will be using the functions in customerlib.py. Also, you
must create an empty text file called customers.data, or save the following sample
data (which already has two customers: Bart Simpson, and Wilbert Johnson) to the
same folder as your program. Now, you can use the function customerlib.write() in your
order form and customerlib.find() in your purchase history.



what am I supposed to do with the customerlib.py?? :confused:

Comments

  • IVTIVT
    edited August 2010
    JLee;64863 said:



    what am I supposed to do with the customerlib.py?? :confused:
    use the functions in it.
  • edited August 2010
    More specifically: put it in the same directory as your assignment, then add the line:

    import customerlib

    at the top of your python script.

    Now you can call the functions like customerlib.write() or customerlib.find(), or whatever else customerlib lets you do.
  • edited August 2010
    Ether;64865 said:
    More specifically: put it in the same directory as your assignment, then add the line:

    import customerlib

    at the top of your python script.
    I did that

    Now you can call the functions like customerlib.write() or customerlib.find(), or whatever else customerlib lets you do.
    that's the part I'm confused about. How do I put those in my python script?
  • edited August 2010
    You just write them in the script like any other function.

    I'm going to assume that this is executed from a web server, since it's CMPT 165, and you're getting the data from some post variables. You probably want something like:

    import cgi

    fdata = cgi.FieldStorage()
    customerlib.write( fdata['first_name'], fdata['last_name'], fdata['amount'])

    where first_name, last_name, and amount are the fields from the form on your submit page.
  • edited August 2010
    thanks for the help :) I figured it out.

Leave a Comment