0

Why this algorithm returns no output? Please help.

# Expected output: 'tuxtax! tuxtax!' for False def echo_sabre(func, x, y): return func(func(x, y), func(x, y)) a = 'tux' b = 'tax' def merge(x, y): return x + y def maruhacho(): while False: print (echo_sabre(merge, a, b, "!")) if True: print ("Qui, qui, je vois") else: maruhacho() 1==2

10th May 2020, 6:53 AM
Timur Musin
Timur Musin - avatar
6 odpowiedzi
+ 5
Because of the condition: while False: is always fixed 2nd thing you have defined function with 3 parameters and while calling in another function you have passed 4 parameters. 3rd thing what is 1== 2 in your code.
10th May 2020, 7:10 AM
A͢J
A͢J - avatar
+ 3
First of all, you do not call any function. Second in maruhacho the while loop will never run, because you have a fixed False conditon. It will also always print "Qui, qui, je vois" as there is a fixed True.
10th May 2020, 7:11 AM
Manu_1-9-8-5
Manu_1-9-8-5 - avatar
+ 2
Here one implementation using three arguments, so similar to the original one and one example using a tuple as input (*args), so that you are flexible in the amount of strings to concatenate. https://code.sololearn.com/cDj3i2UNY1M5/?ref=app https://code.sololearn.com/cX52cwHGMfK9/?ref=app
10th May 2020, 9:12 AM
Manu_1-9-8-5
Manu_1-9-8-5 - avatar
+ 1
I don't think this can work, echo_sabre takes 3 arguments but you give it 4. `echo_sabre(merge, a, b)` will give you "tuxtaxtuxtax". We can substitute in our heads to see: def echo_sabre(merge, "tux", "tax"): return merge(merge("tux", "tax"), merge("tux", "tax")) You could `echo_sabre(merge, a, merge(b, "! "))` to get the expected result, or something very close anyway.
10th May 2020, 8:49 AM
Schindlabua
Schindlabua - avatar
0
Manu_1-9-8-5 AJ #Infinity Love Hello and thank you! So, I attempted to call the maruhacho function by checking 1==2 statement. How do I call it correctly to get the “tuxtax tuxtax” result?
10th May 2020, 8:08 AM
Timur Musin
Timur Musin - avatar
0
Manu_1-9-8-5 Thank you, mate! Really appreciate your input!
11th May 2020, 9:46 AM
Timur Musin
Timur Musin - avatar