Python variable and input challenge. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Python variable and input challenge.

Write code to change output without changing the original code. https://code.sololearn.com/cIcl0J64wnb7/?ref=app

16th Dec 2020, 5:30 AM
Jubaer Rahman
Jubaer Rahman - avatar
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
16th Dec 2020, 5:54 AM
noteve
noteve - avatar
16th Dec 2020, 5:56 AM
Jubaer Rahman
Jubaer Rahman - avatar
+ 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
16th Dec 2020, 5:44 AM
noteve
noteve - avatar
+ 1
😊😊🙏
16th Dec 2020, 5:58 AM
Jubaer Rahman
Jubaer Rahman - avatar
0
I said, solve this problem without changing the code. You can add code but can't change the original code.
16th Dec 2020, 5:46 AM
Jubaer Rahman
Jubaer Rahman - avatar
0
Ohh ok, so can add.
16th Dec 2020, 5:46 AM
noteve
noteve - avatar
0
Yes
16th Dec 2020, 5:47 AM
Jubaer Rahman
Jubaer Rahman - avatar
0
Wait... Is this a real Problem/Doubt or just another challenge? Just want to make sure you're not messing around in qna.
16th Dec 2020, 5:50 AM
noteve
noteve - avatar
0
I stumbled upon it while studying from another site.
16th Dec 2020, 5:52 AM
Jubaer Rahman
Jubaer Rahman - avatar
0
Thank you
16th Dec 2020, 5:52 AM
Jubaer Rahman
Jubaer Rahman - avatar