Changes

Jump to: navigation, search

OPS445 Online Lab6

209 bytes removed, 15:48, 20 January 2023
wget addr switched to github
== PART 2 - Understanding Class Structure ==
<blockquote style="margin-left:35px;">{{Admon/note|style="padding-left:25px"|NOTE|If your professor is asking you to submit labs on GitHub, first follow their instructions on Blackboard to clone the lab6 repository.}}</blockquote>
 
:# First is the definition of the class:<source lang="python">
class Student:
# Add new courses for student1
student1.addGrade('uli101', 4.0)
student1.addGrade('ops235ops245', 3.5)
student1.addGrade('ops445', 3.0)
student1.name = 'Jack'
print(student1.name)
print(len(student1.name))
</source>
:# The final part to creating objects is understanding how to pass values into newly created objects, such as, '''student2 = Student('Jessica', '023384103')'''. How did it know that Jessica is the name instead of the long string of numbers? This is done when the class is written, inside the __init__() method. Look at the arguments used for in the __init__ definition:<source lang="python">
=== 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 takenpassed.
:#Create the '''~/ops445/lab6/lab6a.py''' script.
:#Use the following as a template(warning this is NOT the same as student.py):<source lang="python">
student1 = Student('John', '013454900')
student1.addGrade('uli101', 1.0)
student1.addGrade('ops235ops245', 2.0)
student1.addGrade('ops445', 3.0)
Student Number: 013454900
GPA of student John is 2.0
['ops445', 'ops235ops245', 'uli101']
Student Name: Jessica
Student Number: 123456
cd ~/ops445/lab6/
pwd #confirm that you are in the right directory
ls CheckLab6.py || wget 'https://ictgithub.senecacollege.cacom/~eric.brauersenecaops445/ops445lab6-template/labsblob/LabCheckScriptsmaster/CheckLab6.py?raw=true' -O CheckLab6.py
python3 ./CheckLab6.py -f -v lab6a
</source>

Navigation menu