Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Learning goals: - Learn how to create a class. - Learn how to create object methods. - Learn how to interact with instances of classes.

image text in transcribed

Learning goals: - Learn how to create a class. - Learn how to create object methods. - Learn how to interact with instances of classes. Task: In this class, we are covering classes (pun intended). Python is a so-called Object Oriented Programming language, which essentially means that almost everything in Python is an object. Objects are simply a collection of data and methods that act on those data. A string is for examlpe an object, and so are data structures like lists and dictionaries: these objects hold data and bring methods that can be used on that data (think of the string or list methods). A class is a blueprint to create these objects. As many objects as you like can be instantiated from one class. Classes define the variables (object properties) and functions (object methods) for that object. A Car class could have the properties color, brand, and type, and from that class, we can instantiate objects (or instances) based on that blueprint: a green_honda_civic = Car(Color.GREEN, "Honda", "Civic")or black_tesla_3 = Car(Color.BLACK, "Tesla", "Model 3"). Another common blueprint in the real world is the passport. All passports must contain basic information (object properties) like first name, last name, date of birth, country of birth, and expiration date. As many passport objects as required can be created from this one blueprint. Furthermore, functions (object methods) need to be created to check if any given one of these passports is still valid, to check data for security reasons, and to summarize all data in a human-readable format. For this assignment, you will create the Passport class in passport.py. It should have 4 functions: - _init_ function: takes all data to populate the object properties of this class: first_name, last_name, dob, country, and exp_date. The dates should be given as strings in ISO format and parsed to a datetime.date object using the datetime module. - is_valid function: returns True if the expiration date did not pass yet (exclusive). - summary function: returns a (string) summary with human-readable information about the passport. The output should be along the lines of This passport belongs to Alan Turing, born on 1912-06-23 in The United Kingdom. It is invalid.. Make sure to include whether the passport is valid or not, by using the is v alid method for this. - check_data function: should take the first_name, last_name, dob and country as arguments and should check if that data is exactly the same as the passport object and if the passport is still valid (i.e. check that the passport did not expire using the is_valid method). It should only return True if all is correct. As all of these methods reference a current instance / object of the class, their first parameter / argument should be self. You can use the self variable to reference the current object, its properties, and its (other) methods. After you have created this class and its methods, you should be able to create instances / objects of this class. If you use CodeGrade's editor, the autograder will do this for you. If you use your own editor you can do this in the if _ name_ = = "_main_": block or you can run python3 interactively and import your Class using from passport import Passport

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

LO1 Discuss four different views of motivation at work.

Answered: 1 week ago

Question

LO6 Summarize various ways to manage retention.

Answered: 1 week ago