+ 2
Python variable and input challenge.
Write code to change output without changing the original code. https://code.sololearn.com/cIcl0J64wnb7/?ref=app
11 Answers
+ 1
Oh ok, so from the last code bit I posted.
You can use comma to seperate variables and change the variable at the same time.
For example:
- - - - - - - - - - -
a = 1
b = 2
a = b
b = a
print(a,b)
>> 2 2 #So this is obviously wrong, the reason is the value of variable a is changed first before swapping.
- - - - - - - - - - - -
a = 1
b = 2
a, b = b, a
print(a, b)
>> 2 1 #Variables are swapped
+ 2
Solution can be written as
https://code.sololearn.com/cmT1f9TvQEjk/?ref=app
+ 1
Here are some possible methods.
But I dont know why it is neccessary to not to change the code at all, cause if you dont change the code even just by little replacement, nothing will happen. Maybe the statement means to not to change the code structure but you can change variables??
https://code.sololearn.com/cqIOdIRpecTJ/?ref=app
+ 1
đđđ
0
I said, solve this problem without changing the code. You can add code but can't change the original code.
0
Ohh ok, so can add.
0
Yes
0
Wait... Is this a real Problem/Doubt or just another challenge?
Just want to make sure you're not messing around in qna.
0
I stumbled upon it while studying from another site.
0
Thank you