a and b identical? equal? or error for each one Choose the correct answer for ea
ID: 3854834 • Letter: A
Question
a and b identical? equal? or error for each one
Choose the correct answer for each question regarding the program. def isIdentical(a, b): if a is b: print(a, "is identical with", b) else: print(a, "is not identical with", b) def isEqual(a, b): if a == b: print(a, "is equal to", b) else: print(a, "is not equal to", b) a = 1 b = None #Line A| isIdentical(a, b) isEqual(a, b) What does the output indicate? What does the output indicate if Line A is replaced by b = 1.0 What if Line A is replace by b = 1 What if Line A and the previous are replaced by a = None and b = None?Explanation / Answer
(A) Code :
#!/usr/bin/python
# Function definitions is here
def isIdentical(a,b):
if a is b:
print(a, "is identical with", b )
else :
print(a, "is not identical with", b )
def isEqual(a,b):
if a == b:
print(a, "is equal to", b )
else :
print(a, "is not equal to",b )
a = 1
b = None
isIdentical(a,b)
isEqual(a,b)
OUTPUT :
$python2.7 main.py
=> Because 1 and None are neither identical and nor equal. Those are full different
######################################################################
(B) Code :
#!/usr/bin/python
# Function definitions is here
def isIdentical(a,b):
if a is b:
print(a, "is identical with", b )
else :
print(a, "is not identical with", b )
def isEqual(a,b):
if a == b:
print(a, "is equal to", b )
else :
print(a, "is not equal to",b )
a = 1
b = 1.0 #LINE A
isIdentical(a,b)
isEqual(a,b)
OUTPUT :
$python2.7 main.py
=> Because 1 and 1.0 are equal values . But those are not identical (1.0 is not be 1)
#######################################################################
(c) Code :
#!/usr/bin/python
# Function definitions is here
def isIdentical(a,b):
if a is b:
print(a, "is identical with", b )
else :
print(a, "is not identical with", b )
def isEqual(a,b):
if a == b:
print(a, "is equal to", b )
else :
print(a, "is not equal to",b )
a = 1
b = 1 #LINE A
isIdentical(a,b)
isEqual(a,b)
Output :
$python2.7 main.py
=> Because 1 and None are identical and equal. Those are are same.
######################################################################3
(D) Code :
#!/usr/bin/python
# Function definitions is here
def isIdentical(a,b):
if a is b:
print(a, "is identical with", b )
else :
print(a, "is not identical with", b )
def isEqual(a,b):
if a == b:
print(a, "is equal to", b )
else :
print(a, "is not equal to",b )
a = None
b = None #LINE A
isIdentical(a,b)
isEqual(a,b)
Output :
$python2.7 main.py
=> Because 1 and None areidentical and equal. Those are same .Both are None
####################################################################
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.