Lab 2

Part 1 Using the debugger
  1. Create a working directory e.g. lab2 and download the source files from Canvas. Create a PyDev project for this week or use an existing one.

  2. Import "isPrime.py" into the project created, right-click line 13 to set a breakpoint

  3. Click "Open Perspective" icon next to the search glass icon or Window->Perspective->Open Perspective->Other... to use the debugger

  4. Before launching the debugger to execute each line of code, type the expressions to examine their values at the breakpoint.

  5. Click the debugger icon or Run->Debug As->Python Run to launch the debugging process, enter any number in the input prompt e.g. 91

  6. Check if values of expression are as expected and click Resume button to continue the execution of the program
  7. Try to use different input and breakpoint to trace the program.

  8. Right-click the Debugger Perspective icon to close when finished.

Part 2 CGI Python script and HTML
  1. Install the XAMPP for Windows by Apache Friends
    apachefriends.org

  2. Find the XAMPP control panel from the Windows menu. Click it to start and you will see the below screen.

  3. Click the config button, Add .py to the "AddHandler cgi-script ..." line in the file "httpd.conf"

  4. save file and click the "start" button to start the Apache server

  5. Download the source files from week1 tutorial folder.

  6. Copy all "cgi*.py" to your "xampp/cgi-bin/" directory, copy "cgilogon.html" file to "xampp/htdocs/" directory

  7. Modify python location in first line of all "cgi*.py" file. Use IE to test all program.

Part 2 Programming exercises.

  1. Here are 6 integers : 1, 7, 3, 2, 0, 5. Use diagrams to show the steps of sorting the integers into ascending order using bubble sort. Given "bubblesort.py" in Lab 2 tutorial folder, check your answer using breakpoint in Eclipse debugger.

  2. In "SBapp.py", sorting of Client List was done using Python sorted() method i.e. "sorted(clientDL, key = lambda c: c.name)". Modify bubblesort.py and use bubblesort() to do the sorting in "SBapp.py".

  3. Test "SBapp.py" with the following data files and transactions:

    Add the test cases to "SBappTestReport.html" and modify the program to fix the error. Identify the part of program code that causing the errors; add exception handling to handle all errors found.

  4. modify "cgilogon.py" to display a link to your personal web page or any other page of your choice.

    Submit "cgilogon.py" after you finished.

  5. Change the loantable application to run on a server, and display the output in the browser as below.


    Loan amount:
    Interest:         
    Payment:       


    MonthStarting
    Balance
    PaymentMiddle
    Balance
    InterestEnding
    Balanace
    1 300.00 100.00 200.00 2.00 202.00
    2 202.00 100.00 102.00 1.02 103.02
    3 103.02 100.00 3.02 0.03 3.05
    4 3.05 3.05 0.00 0.00 0.00