CHK121COM Introduction to Computing

Time Table

Lab 6

Lab 5

Lab 4

Lab 3

Lab 2

Lab 1

Part 1 Software installation
  1. Download and install the latest Python version for Windows python.org

  2. Istall Java SE JDK for Windows Java SE Downloads

  3. Eclipse C/C++ version Get lastest Eclipse

  4. Enter workspace directory to Launch Eclipse C/C++ version

  5. Install PyDev into Eclipse:
    • Start up Eclipse
    • Under "Help -> Eclipse Marketplace... ", enter "pydev" in "Find:" search dialog box, and install the PyDev item

    • Check next and follow the instruction to complete the installation of PyDev

  6. To configure Pydev
    • Click Window -> Preferences.
    • Go to PyDev -> Interpreters -> Python Interpreter
    • Click the button "Config first in PATH" and "Apply and Close" to finish the configuration.

Part 2 PyDev console script and module
  1. To test the Eclipse Pydev IDE
    • Go to File -> New -> Project.

  2. Select PyDev Project, then click Next. On the next page, type "week1lab" or name of your choice in the Project name field. Creat a working directory or use the default one. Select Grammar version (Same as interpreter) and Interpreter (Default -- currently: Python) and click Finish.

    You will see a Pydev perspective opened inside the workbench with the new PyDev project in the Package Explorer.

  3. Pydev Console

    • Go to Window -> Show View -> Console.
      Click the new console icon and select "Pydev Console"

    • From the next dialog window, select Python Console and click OK.

  4. Simple Canvas drawing
    • To draw a simple logo

    • In PyDev Console, enter the followings:
      
      from tkinter import Tk, Canvas
      frame=Tk()
      canvas=Canvas(bg='black',height=250,width=300)
      coord=(100, 100, 200, 200)
      canvas.create_arc(coord,start=0,extent=90,fill='white')
      canvas.create_arc(coord,start=90,extent=90,fill='blue')
      canvas.create_arc(coord,start=180,extent=90,fill='white')
      canvas.create_arc(coord,start=270,extent=90,fill='blue')
      canvas.pack()
      frame.mainloop()
      

  5. Creating a new Pydev Module bmw

    In the Package Explorer view, select the the current working pydev project i.e. week1lab and click the New > Source Folder... to create a source folder "src", click the New > Pydev Module... in the toolbar. In the Package and Name field, select src and type bmw. Click Finish and Select <empty> from the Template menu.

    bmw.py is opened in the editor which contains the default header comments. Finish the program by copy the code from above. Save and run the module to see your output.

Part 3 IDE file import and run configuration operations

  1. Create a working directory e.g. week1 and download the source files from Lab1 tutorial folder in Canvas. Create a PyDev project for this week or use an existing one.
  2. Import files into the project

    In the Package Explorer, make sure that the current working project is selected. Select the menu item File > Import....

    Select File system, then click Next.

    In the Import wizard, specify the source directory and the target PyDev folder. Below the hierarchy list click Select All. You can expand and select elements within the working directory on the left pane to view the individual resources that you are importing on the right pane.

    Click Finish to finish the import.

  3. Using the Editor

    You can open any file in the project explorer by double clicking on it. Or create a new PyDev module i.e. File > New > PyDev Module. Notice the syntax highlighting. Different kinds of elements in the Python source are rendered in unique colors. Examples of Python source elements that are rendered differently are:

    Multiple lines '''...''' comments
    inline # comments
    Keywords and String

  4. Running a Python Module

    In the Package Explorer view, find tester and double-click it to open it in the editor.

  5. Using the drop-down Run button in the toolbar, select Python Run from the cascading Run As menu. This will launch the Module in the active editor after prompting for saving files changed.

    Except the file "quadratic.py" which uses argument inputs, test run and study all programs under the "src" folder.

  6. Using arguments of main()

    Select the programe which will make use of arguments as input i.e quadratic.py, select Run Configuration... under Run Menu

  7. Enter arguments for main() e.g. 1 1 -12 and click run; result of the simple quadratic equation solver program will be displayed in the bottom console.

Part 4 Individual Assignment

  1. Create a working directory assignment, download asgn1student.zip from Assignment folder, gradeV0.py and Student121V0.py from Lab1 Tutorial folder. Extract and import all programs and data files into Eclipse.

  2. Install matplotlib

  3. Test run "grade.py" and "gradeV0.py"

  4. Using reference from matplotlib.org and examples from Lab1 tutorial folder, modify gradeV0.py to print a list of students and produce a bar chart of grade distribution as follow.

Part 5 Programming exercises.

  1. Install UMLet from Eclipse Marketplace, draw the class diagram of tkinter.Frame, Circle, and Taichi class in tutorial folder.

  2. Write a Python program to output nine Taichies as follow.

  3. Given the following program to draw a simple logo using Canvas widget from tkinter module

    
    from tkinter import Tk, Canvas
    frame=Tk()
    canvas=Canvas(bg='black',height=250,width=300)
    coord=(100, 100, 200, 200)
    canvas.create_arc(coord,start=0,extent=90,fill='white')
    canvas.create_arc(coord,start=90,extent=90,fill='blue')
    canvas.create_arc(coord,start=180,extent=90,fill='white')
    canvas.create_arc(coord,start=270,extent=90,fill='blue')
    canvas.pack()
    frame.mainloop()
    
    The Canvas class supports more than canvas.create_arc() methods to draw arc or pieslice. Other methods include create_line(),create_oval(),create_polygon(), create_rectangle(), and create_text(). Modify the program above to draw a rectangle and print your name with a line drawn underneath.

  4. Using functions included in "triangle" sctipts from tutorial folder, write a a script which prompts user for three points of a triangle, draws the triangle with area and points printed if the points are valid; otherwise, an error message should be printed.

  5. Write a function triangleStar() that displays two triangles pointing up and down. The function uses three parameters to position and size the triangle:
    • x - the x-coordinate of the top left corner of the bounding box of the triangle
    • y - the y-coordinate of the top left corner of the bounding box of the triangle
    • size - the length of each size of the bounding box of the triangle

    The triangle must consist of three lines. The base and height of the triangle must be of length size. The base of the triangle must be parallel to the x-axis. The two sloping sides of the triangle must be equal in length. The top left corner of the bounding box of the triangle must be positioned at (x,y). Below is a diagram depicting the resulting star, the trangles, and its bounding box, completed with dimensions and positions.

  6. Rewrite the "loanTable.py" program in Lab1 tutorial folder to use command-line arguments instead of prompting user for input. For example: typing "python loantable.py 300 12 100" in command prompt console will produce an output as follows:
    	The loan amount is : 300
    	The annual interest rate is: 12
    	The monthly payment is: 100
    
    		Starting            Middle              Ending
    	Month	Balance   Payment   Balance   Interest  Balance
    	-------------------------------------------------------
    	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
    
    Modify the program to write output into a file using HTML, upload file "output.html" to github after you finished.