Python Forum
Need help with this Python Interview Question
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with this Python Interview Question
#1
Hey,

Let func = lambda a, b : (a ** b), what is the output of func(float(10),20) ?

Please can some share their approach to solve this problem?

Source: https://www.interviewbit.com/python-inte...questions/

Thanks in advance..!
likes this post
Reply
#2
what happens when you run the code? :-) i.e. there is nothing complicated as to what the output would be (multiplying float and int).
note that this example goes against PEP8 recommendations, so I would definitely mention it in an interview
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Actually, was unable to figure out the approach to solve this 1e+20.

Got it, btw thanks:)

Simple things seem complicated to me;)
Reply
#4
def exp10(value, exponent):
    return value * 10 ** exponent
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#5
(Sep-11-2020, 11:32 AM)hannah Wrote: Actually, was unable to figure out the approach to solve this

Why? What didn't you understand about the code?
Reply
#6
(Sep-11-2020, 11:32 AM)hannah Wrote: 1e+20
there is nowhere 1e+20 in the question

Ah, I see - it's in the answers
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
Disclaimer: M a newbie in coding, trying to apply logic seems difficult sometimes.

But appreciate ya'll responding, will be back with more doubts whenever I come across.
Reply
#8
There isn't really any "logic" in the code you posted, it's just a calculation. Assuming you know what the ** operator is and how functions work, you should be able to understand how it works (and if you don't understand those things, you'll likely need to study them more).
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020