.Please post answer who is expert in Python!! so I wanna answers of Python OOP e
ID: 3876191 • Letter: #
Question
.Please post answer who is expert in Python!! so I wanna answers of Python OOP experts
Explain the following code how its work step by step then show what its print out but DONT POST ONLY OUTPUT as I said explain step by step
def test A(): raise ValueError() def test B(): raise TypeError() def test_c): raise KeyError def test_D(): return "Hello" def status function ): retval-0 try: except ValueError: except TypeError: except Exception as e: retval - function() retval = 10 retval = 22 retval 35 retval+= retval retwal 2 else: inally: return retva.l print status testA)) print ( status( test_B)) print ( status( test C)) print status( test_D))Explanation / Answer
Output
Explanation
print(status(test_A))
''' Output : 20
Raises value error which puts retval = 10
then finally before returning retval*=2 = 10*2 = 20
'''
print(status(test_B))
''' Output : 44
Raises Type error which puts retval = 22
then finally before returning retval*=2 = 22*2 = 44
'''
print(status(test_C))
''' Output : 70
Raises key error which puts retval = 35
then finally before returning retval*=2 = 35*2 = 70
'''
print(status(test_D))
'''Output: HelloHelloHelloHello
test_D returns "Hello"
It comes to else condition in status function and retval += retval which makes retval to be HelloHello
Then finally retval*=2 = HelloHello*2 = HelloHelloHelloHello
'''
Hit thumbs up if you are satisfied with the solution. Next time on wards please paste the code instead of putting an image. That makes answering easier. Happy Learning!
Output
20 44 70 HelloHelloHelloHello
Explanation
print(status(test_A))
''' Output : 20
Raises value error which puts retval = 10
then finally before returning retval*=2 = 10*2 = 20
'''
print(status(test_B))
''' Output : 44
Raises Type error which puts retval = 22
then finally before returning retval*=2 = 22*2 = 44
'''
print(status(test_C))
''' Output : 70
Raises key error which puts retval = 35
then finally before returning retval*=2 = 35*2 = 70
'''
print(status(test_D))
'''Output: HelloHelloHelloHello
test_D returns "Hello"
It comes to else condition in status function and retval += retval which makes retval to be HelloHello
Then finally retval*=2 = HelloHello*2 = HelloHelloHelloHello
'''
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.