Out of syllabus-OOps concepts-Operator overloading

299 views
Skip to first unread message

Kamala Malar

unread,
Oct 29, 2023, 7:01:02 AM10/29/23
to Discussion forum for The Joy Of Computing Using Python

1. Which function is called when the following Python code is executed?

f = foo() format(f)

a) format()
b) __format__()
c) str()
d) __str__()

We are not having oops concept in our syllabus but in yesterday question I got this one . So this should be considered.


Ajinkya Kerkar

unread,
Oct 29, 2023, 7:29:55 AM10/29/23
to Discussion forum for The Joy Of Computing Using Python, Kamala Malar
Being a total beginner as this was my very first course & relying solely on the syllabus of this course, as it was assured that questions will be based on concepts covered in the syllabus.. I was totally dissappointed when I saw questions based on concepts not covered in syllabus during the final exam. 

It is really dissapointing to lose marks over question based on concepts not covered in syllabus, especially when you're fully prepared to answer any & every question related to the topics covered in the course.

Not sure if there were different sets for this exam, but yes I got that "format(f)" question too!
There were at least 4-5 questions which where on concepts not covered in the syllabus.

There was also one question with " x>>2 " or "x<<2" & I had no clue what that's supposed to do :(

then there was something with 
list = [ 1,2,3,4, "hello", " ", [ ] ]
list(filter(bool, 1 or something similar to that)

what does that even do? :/

Then there was one question which I can't recall now, which had all the wrong answers in option.

Ajinkya Kerkar

unread,
Oct 29, 2023, 7:38:26 AM10/29/23
to Discussion forum for The Joy Of Computing Using Python, Ajinkya Kerkar, Kamala Malar
BTW, could you please explain to me how this question can be solved using pen & paper?
I was dumbfounded during exam when my answer was different from options avaliable. Even though I believe there was correct answer among the options for this particular question.

def log(x, y):
    if x < y:
        return 0

    return 1 + log(x//y, y)

log1 = log(256,16)
log2 = log(32, 4)
log3 = log(8, 3)

print(log1, log2, log3)

Values of log2 & log3 might be different as I can't exactly recall them any more.

I'd appreciate if you could show me how to solve it, just getting the value of "log1" would be suffice for me to understand how it's done.

S Neeharika Jaiswal

unread,
Oct 29, 2023, 8:24:48 AM10/29/23
to Discussion forum for The Joy Of Computing Using Python, Ajinkya Kerkar, Kamala Malar
WhatsApp Image 2023-10-29 at 17.49.59_7cb125e1.jpg

Ajinkya Kerkar

unread,
Oct 29, 2023, 9:35:57 AM10/29/23
to Discussion forum for The Joy Of Computing Using Python, S Neeharika Jaiswal, Ajinkya Kerkar, Kamala Malar
@S Neeharika Jaiswal

    Thank you so much for such a thorough explanation with every single step. I understand it well now.
 I was able to get the value till 1+log(1,16), but couldn't figure out how to proceed beyond that.. lol 
I forgot to factor in the recursive alogorithm to sum up the value & assumed it the answer as 0 which was not among the options. :p

Thanks & Regards,
      Ajinkya

Kamala Malar

unread,
Oct 29, 2023, 12:18:26 PM10/29/23
to Discussion forum for The Joy Of Computing Using Python, Ajinkya Kerkar
@Ajinkya Kerkar 
You might have heard about XOR operator. Similarly << operator will shift the number by left. Operand1<<Operand2. It will shift operand1 left by operand2 times.
you will shift the binary digit left for left shift. Or else you can multiply by 2 also for left shift and divide by 2 for right shift.
shift_left.jpg


Kamala Malar

unread,
Oct 29, 2023, 12:26:05 PM10/29/23
to Discussion forum for The Joy Of Computing Using Python, Ajinkya Kerkar
for filter method, hope you might familiar with map () which is used to get input as string and convert to list of integer number in programming assignment. Similarly filter method. Filter() is used to filter out list of values based on some criteria in the given input. Filter() also takes 2 argument function and input iteratable. Here list of values as input, you have to apply bool function when which items and all in the input sequence its True that will be returned as output

Note
bool() is used to give True or False value based on input, for any input other null value like data type  "",0,0.0,[] is will return True. Empty value will be false. you can refer output screenshot
filter.jpg

Ajinkya Kerkar

unread,
Oct 29, 2023, 12:48:25 PM10/29/23
to Discussion forum for The Joy Of Computing Using Python, Kamala Malar, Ajinkya Kerkar
Thank you so much @Kamala Malar for providing solution to my queries, I'll surely go through after dinner or in the morning & will reply if I still couldn't comprehend that. 

Kamala Malar

unread,
Oct 29, 2023, 12:52:59 PM10/29/23
to Discussion forum for The Joy Of Computing Using Python, Ajinkya Kerkar, Kamala Malar
@ Ajinkya Kerkar,
Thank you so much . You are keen in learning. Knowledge can be gain only if you share it. thats what I believe. So its my pleasure to help you.

Ajinkya Kerkar

unread,
Oct 30, 2023, 1:37:16 PM10/30/23
to Discussion forum for The Joy Of Computing Using Python, Kamala Malar, Ajinkya Kerkar
LOL what a relief to know that the answer I chose for that filter() bool question was right xD
Even though I had no clue if that was even a valid function, I just guessed it might be one of those Out of syllabus question & the way bool works it could that one.

Thanks for taking time to explain me in details about the way it works, with your help now I know precisely how it works.

Also, regarding that left shift operator.. NGL, but initially I had no clue what you had written & I couldn't make any sense of it at first glance. But after experimenting about an hour with the values you've written & playing around with different values in interpreter & a lil bit of RND on google. Now, I can comprehend each and every bit of it & the credit goes to you. Hell I can even write any number in binary & vice versa now! feels great to learn something new. :D 

Wish I had known more about these operators, methods & functions before exam, I would've done better.
But hey, better late than never I guess. `\( ' .')/`

Once again Thank you very much! I really appreciate all your help. Keep up the good work! :)
Reply all
Reply to author
Forward
0 new messages