Last active
March 6, 2020 04:28
-
-
Save DxPoly/6b0c08131de1cf6e859f7f0db2205da5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Question 1: polymorphism - define a function called addall() | |
def addall(x,y): | |
if type(x) != type(y): | |
print 'Test for the function call, addall(',repr(x),',',repr(y),'): The data you entered is not correct.' | |
elif type(x) in [int, float, list, tuple]: | |
print 'The function call, addall(',repr(x),',',repr(y),'), returns',x+y,'.' | |
elif type(x) == set: | |
print 'The function call, addall(',repr(x),',',repr(y),'), returns',x|y,'.' | |
elif type(x) == dict: | |
z = {} | |
z.update(x) | |
z.update(y) | |
print 'The function call, addall(',repr(x),',',repr(y),'), returns',z,'.' | |
else: | |
print 'Test for the function call, addall(',repr(x),',',repr(y),'), returns: The data you entered is not correct.' | |
addall(1,2) | |
addall(1.1,2.2) | |
addall([1,2,3],[10,20,30]) | |
addall((1,2,3),(10,20,30)) | |
addall({1,2,3}, {10,20,30}) | |
addall({'a':1,'b':2}, {'e':10,'f':20}) | |
addall(1,'2') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment