5 Hardest Python Questions!

Confuse your pythoneer friends with these questions

Ishaan Gupta
CodeX

--

Photo by Monstera from pexels

Link for the Part-2 of this story —

1.) round() function 😵‍💫

What do you think is the result of the following code:

print(round(9/2))
print(round(7/2))
print(round(3/2))

Answer: 4, 4, 2

Why does print(round(7/2)) prints 4 instead of 3 or why does print(round(9/2)) prints 4 instead of 5?

This is because, in python, the round function implements banker’s rounding, where all the half values are rounded to the closest even number.

2.) Instances! 🥸

Guess the output?

class A:
answer = 9
def __init__(self):
self.answer = 10
self.__add__ = lambda x, y: x.answer + y

def __add__(self, y):
return self.answer - y
print(A() + 4)

Answer: 6

--

--

Ishaan Gupta
CodeX
Writer for

Medium Top Writer. CSE Sophomore. Programmer. Developer. Finance Enthusiast. Join Medium Membership https://ishaangupta1201.medium.com/membership