0
Why the answer is 55?
x=10 y="5" for i in y: # i has only index 0, right? x,y=y,x # totally new to this assignment form, what does this mean? x*=y//5 # does this mean x=Ă*(y//5)????? print(x)
9 Respostas
+ 5
x, y = y, x
Switches the values around so x is "5" and y is 10.
x *= y // 5 # x = x * (y // 5)
x is a string "5". y (10) // 5 is 2 when you times a string you repeat it nth times in this case twice ("5" * 2) so x becomes 55.
+ 5
I wonder who comes up with codes like this one. I mean, they don't really teach anything, mostly they don't even make sense.
for i in '5' will iterate over the single characters of the string '5' and set i to each of the characters.
for i in 'hello':
print(i)
would print h, e, l, l, o (without commas, each letter in a new line).
There's only one character in '5', so the loop will only be executed once. The variable i isn't really needed.
x, y = y, x swaps the values of the variables x and y. Now x is the string '5' and y is the integer 10.
x*=y//5 => y is 10, // is integer division. 10//5 = 2. So it's the same as '5'*2. In python, print(n * 'string') leads to 'string' being printed n times. That's why the final result is '55' (as a string, not an integer).
+ 2
Take a screen shot đ
+ 1
Anna this is a code brought to me by random challenge here in solo learnđđ yes I agree with you this is a weird code, however it triggers my brain to thinkđ
+ 1
Roberto After match end (Both side finished not declined or expired), you can view the correct answer down and the entrance is below the table with tick and cross.
0
many thanksđhope you'll have the same easiness and cleareness to explain and teach "apparently difficult" issues like these đ
0
Does anybody like me, already disliked, hates or got mad about the fact that challenge countdown in sololearn are too short??? I mean, apart the fact someone lost the challenges is there a way to save the question or code for our own future study?
0
yes...I forgot to mention that I'm tired of taking screenshotsđ€ŁI was wondering if is there a database here of challenge questions or similar..