Changes

Jump to: navigation, search

OPS435 Python3 Lab 6

21 bytes removed, 21:55, 3 November 2019
LAB REVIEW
* Programmer-defined types
* Class Object
* Class methodsfunctions: __init__, __str__, etc* Class instance: attributes and methods
* Object instantiation
* Object Attributes: data attributes and methods
* Pure Function
* Scopes and Namespaces: local, nonlocal, and global
* Class definition syntax
* Class and Instance variables
* Iterators and Generators
 
* Operator overloading
= INVESTIGATION 1: Creating Classes =
:#Place the following content inside the new python script and save it. Read through this script and the comments inside.<source lang="python">
#!/usr/bin/env python3
# Author idID: [seneca_id]
class Student:
=== Create a Python Script Demonstrating Classes ===
:# The following python script is broken. It has two major problems to fix and one new feature to add: <br />'''first problem ''' is providing the student number as an integer causes an error(TypeError) when displayStudent() is run, <br />'''second problem ''' is in displayGPA() may divide by zero(ZeroDivisionError) if no courses are added to the dictionary or the grades added to the dictionary are 0.0 floats. <br />'''Finally''', you will add a new method to this class that prints out a formatted list of all courses the student has taken.
:#Create the '''~/ops435/lab6/lab6a.py''' script.
:#Use the following as a template(warning this is NOT the same as student.py):<source lang="python">
#!/usr/bin/env python3
# Author ID: [seneca_id]
class Student:
# What is self used for in an object?
# What does it mean to instantiate an object?
# Import the Student class into ipython3python3, instantiate some objects, and try changing different attributes, and adding new attributes.
# Make a copy of lab6a.py called lab6practice.py, make the Student class accept another argument called program. When you create the new object: student = Student('name', '123456789', 'CTY'). Can you print the new students program out with student.program?
# Create a new method in lab6practice.py that checks to make sure the program is either "CTY" or "CNS", if it's not one of these, change the value to "unknown". Make sure the attribute is changed after your object is created.
1,760
edits

Navigation menu