I&C SCI 31 Lecture Notes - Lecture 6: Grace Hopper, Boolean Expression
Document Summary
## step 1: set it up (say this once at the top of the program: from collections import namedtuple. ## step 2: define what your object looks like. # a student has a name, id, major, and gpa. Student = namedtuple("student", "name id major gpa") #blueprint student_1 = student ("peter anteater", "111111111", "ics", 5. 0) ## step 4: refer to fields as needed with dot notation: ## now that we learned to create our own functions. ## we can sort on any field we want. ## we just need to write a function def student_id (apprentice:student) -> int: """return id number of a student""" return apprentice. id assert student_id (student_2) == 0000000000. ## the last assertion fails because we defined student id. ## as a string and compared it to an integer def student_id (apprentice:student) -> int: """return id number of a student""" return apprentice. id assert student_id (student_2) == "0000000000"