Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3.7 Problem: Code the program below. All code must be commented appropriately. The program must contain and use a main function that is called

Python 3.7 Problem:

Code the program below. All code must be commented appropriately. The program must contain and use a main function that is called inside of: If __name__ == __main__:

Create a program that contains one class called Person. The Person class should contain an __init__ method that sets the variables for the first name, last name, age, and height (in cm).

Overload the following operators to do as instructed:

+

Return a new instance of Person where The first name is the first objects name + Jr. The last name is the first and second objects last name with a hyphen in between The age is 0 The height is the first and second objects height added together mod 10 plus 30

Example Below: Person(John, Doe, 30, 180) + Person(Jane, Smith, 30, 160) = Person(John Jr., Doe-Smith, 0, 30)

-=

If possible, remove the hyphenated last name from the object

Example Below: Person(John Jr., Doe-Smith, 0, 30) - Person(John, Doe, 30, 180) = Person(John Jr., Smith, 0, 30)

If not possible, change nothing and print out Not Possible (Ensure that None isnt returned and breaks your program)

+=

Allow a tuple containing two pieces of data (age and height) to be passed to and added to the objects current age and height. If a single number is passed instead of a tuple, add it only to the age.

Example Below: Object.age = 10 Object += 10 Object.age == 20 Object.age = 10 Object.height = 100 Object += (10, 20) Object.age == 20 Object.height == 120

==

If all variables in the object are the same, return True, else return False

Example Below: Object == Object True

!=

If any of the variables are different, return True, else return False

Example Below: Object != OtherObject True

> If the age of the first object is larger that the age of the second object, return True, else return False
>= If the age of the first object is larger or equal to the age of the second object, return True, else return False
< If the age of the first object is smaller than the age of the second object, return True, else return False
<= If the age of the first object is smaller or equal to the age of the second object, return True, else return False
str() Return the first and last names of the object formatted like so: John Doe

Create two objects of type Person with the following attributes:

First Name: Bob Last Name: Robert Age: 40 Height: 167 First Name: Alice Last Name: Wonder Age: 38 Height: 170

Use the + first to create a third object of Person.

Use all overloaded operators with these three objects (You do not need to use every single operator from every single object. So long as all operators in general are called you will be fine)

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

Step: 3

blur-text-image

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

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

More Books

Students also viewed these Databases questions

Question

=+ Who are the buyers/users of the products abroad?

Answered: 1 week ago