+ 3

Why my code is not working as expected?

I have written a python3 code that will give input something like that: Input : 12 output: 1 2,3 4,5,6 7,8,9,10 11,12 But in this code it's not working like expected: https://code.sololearn.com/c9C80nn81Jio/#py I have written the same code in c programming with same pattern but this work fine: https://code.sololearn.com/cChAO8Fku0ug/#c Why in py code not working like c?

1st Dec 2020, 11:41 AM
The future is now thanks to science
The future is now thanks to science - avatar
6 Answers
+ 4
Zatch bell In :- for i in range(1,(x+1)): it will constantly set "i" to be the next element in the range 1-(x+1) no matter what, even of you try to change it inside the loop. A simple fix would be to use a while loop instead here is the fix👇 https://code.sololearn.com/ckVE5NkCN3zT/?ref=app
1st Dec 2020, 12:25 PM
Arsenic
Arsenic - avatar
+ 4
Slick let me add spaces in the output to make it much clearer For input = 15 Output should be :- 1 2,3 4,5,6 7,8,9,10 11,12,13,14,15
1st Dec 2020, 12:10 PM
Arsenic
Arsenic - avatar
+ 3
Thanks Arsenic for the suggestion .I have used while loop and it's working fine: https://code.sololearn.com/cV3ilYnWbkh1/#py Slick thank you also for your code.I have now understood how to do it.
1st Dec 2020, 12:36 PM
The future is now thanks to science
The future is now thanks to science - avatar
+ 2
Slick, My output will be like that(If I use \n instead of gap): For input 11: output: 1 2,3 4,5,6 7,8,9,10 11 I am expecting output like that: 1 2,3 4,5,6 7,8,9,10 11
1st Dec 2020, 12:07 PM
The future is now thanks to science
The future is now thanks to science - avatar
+ 1
Im confused by the use of commas in the c code. Why isn't there commas between each number? What is the exact output you're going for?
1st Dec 2020, 11:47 AM
Slick
Slick - avatar