I&C SCI 31 Lecture Notes - Lecture 6: Grace Hopper, Boolean Expression

64 views2 pages

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"

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents