Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this exercise you will write a function that will evaluate any two Python objects in order to provide a numeric score indicating how closely

For this exercise you will write a function that will evaluate any two Python objects in order to provide a numeric score indicating how closely related they are. Create a file named
compare.py with a single function named compare. This function must take two arguments, and must return an integer satisfying the following requirements:
If the arguments contain references to the same object, return 0.
If the arguments refer to different objects with same type and same value, return 1.
If the arguments are the same type, but have different values, return 2.
If the arguments are of different types, return 3.
The following interaction provides some examples of the expected behavior.
a=#1
>b=a
"#"
c+=1
d="#2"
=>e=7
> compare(a, b) # Same object.
0
compare (a,c) # Different objects the same value.
1
compare (c,d) # Same type, different values.
2
> compare(d, e) # Different types.
image text in transcribed

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

2. Compare the sales and service departments at Auto World.

Answered: 1 week ago