+ 12

Why does it print only the second line "xxxxxxx"?

https://code.sololearn.com/cRMt5fLtGR1z/?ref=app

10th Mar 2018, 11:58 PM
Vučko/ВучĐșĐŸ/Vuchko
Vučko/ВучĐșĐŸ/Vuchko - avatar
5 Answers
+ 7
You defined print_text function twice, so when you call print_text function it has the second value: print('xxxxx'). If you want to print two lines you should define two functions with different names and call them both.
11th Mar 2018, 12:15 AM
Vladi Petrov
Vladi Petrov - avatar
+ 1
You could also remove line 10, so you have only one function definition for print_text(), which prints two lines. def print_text(): print("Hello world!") print("xxxxxxx")
12th Mar 2018, 12:29 AM
Marija Stepanović
Marija Stepanović - avatar
+ 1
You re-defined function print_text() (1st time started at line #8, 2nd time at line #10). The program will run with the latest definition of print_text(), printing only "xxxxxxx". Let's try remove line #10 and see if it works as you expected.
12th Mar 2018, 7:20 AM
tin le
0
def decor(func): def wrap(): print("============") func() print("============") return wrap def print_text(): print("Hello world!") print("xxxxxxx") print_text = decor(print_text) print_text(); #this should print both lines.
16th Nov 2018, 1:30 PM
Rawy Murgany
Rawy Murgany - avatar