Thursday, August 18, 2022

[FIXED] What call to the function will result in the following output?

Issue

def doh(a, b, c):
    if a[str(b)] + c == a[c + 'x']:
        print(b + 2)

expect output:

11

Where do I start to approach? And what are these variables type?


Solution

Solution

Pass these values for variable a,b,c

variable a must be a dictionary, variable b should be integer 9 and variable c should be a string or alphabet

#function defenition
def doh(a, b, c):
    if a[str(b)] + c == a[c + 'x']:
        print(b + 2)

a = {'9':'d','cx':'dc'}
b=9
c='c'
doh(a, b, c)

Result

11

Another Solution

a = {'9':'michael','hix':'michaelhi'}
b=9
c='hi'
doh(a, b, c)

So the relation should be like in the following figure. go to this link to see the relation

I hope this would be helpful



Answered By - Littin Rajan
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.