0

I got this question on python challenge, what's the output? And why does this have ; at the end? Python doesn't need that right?

x=67; y=int(".join(sorted(str(x)))); z=int(".join(sorted(str(x)))[::-1]); print(z-y);

23rd Apr 2020, 5:46 PM
Anrico Gideon
Anrico Gideon - avatar
5 Respostas
0
Based on my understanding, I add semi-colon to separate two statements in one line.
23rd Apr 2020, 6:01 PM
Mohsen Cadir
Mohsen Cadir - avatar
0
You can also write like this if you want. (although it's ugly, unreadable & very bad practice) x=67;y=int(".join(sorted(str(x))));z=int("join(sorted(str(x)))[::-1]); print(z-y); for the output, why don't you try in code playground and learn how first. It'll be better for you than straight answer.
23rd Apr 2020, 6:14 PM
The Sylar
0
Ah thanks for the response both of you. I actually did try this code on pycharm but it gave me an error, that's why I came here looking for answer.
23rd Apr 2020, 6:16 PM
Anrico Gideon
Anrico Gideon - avatar
0
Can you show me error output? When i tried above code in sololearn code playground, error is due to using only one double quote (") instead of two ("").
23rd Apr 2020, 6:22 PM
The Sylar
0
Sorry for the late answer, i got it to work, thanks for the help!
24th Apr 2020, 2:34 PM
Anrico Gideon
Anrico Gideon - avatar