I have a question in Python! Which code outputs this???? 1,2,3,4,5,6,7,8,9,10 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

I have a question in Python! Which code outputs this???? 1,2,3,4,5,6,7,8,9,10

I mean the code must divide the numbers by comma in one line! I need different Code! not like print(1,2,3,4,5,6,7,8,9,10)

30th Jul 2017, 1:28 AM
Shadow Windster
Shadow Windster - avatar
24 Answers
+ 11
There are several (and better) ways to do that, i guess. https://code.sololearn.com/ch04ymTr1cw8/?ref=app
30th Jul 2017, 1:55 AM
Maz
Maz - avatar
+ 10
Jakub, that's a nice one! :D Is there a way to remove the brackets "[ ]" in the console output... ? I am not so good in Python yet. :P
30th Jul 2017, 2:08 AM
Maz
Maz - avatar
+ 10
Jakub, it works, thanks for share! $Vengat i was referring to the Jakub's solution (cleaner than mine with loops), your solution checks the last value and remove the comma, i also made something similar but i opted for an easiest solution, just putting a further print statement at the end. Goodnight people! :P
30th Jul 2017, 2:20 AM
Maz
Maz - avatar
+ 9
See it works https://code.sololearn.com/cOKQ0zZ40Hu5/?ref=app I am free to help out in any Pythonian stuff and non-advanced stuff. Kuba is always the best
30th Jul 2017, 2:15 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 8
@Maz you can do: m=len(list)-1 for i in list: print(i, end="") if m: print(",",end="") m-=1
30th Jul 2017, 2:13 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 8
@Sk krish he doesn't want the bracket
30th Jul 2017, 2:16 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 8
Goodnight! Have lots of rest and dont wake up at 2.45am to do sololearning >:P
30th Jul 2017, 2:21 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 8
@Sk for someone who claims to be bad at Python that is pretty awesome.
30th Jul 2017, 2:22 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 8
jakub's answer is very easy & I love it
30th Jul 2017, 2:23 AM
Shadow Windster
Shadow Windster - avatar
+ 8
Yeah it is easy to create the list. I am inspired of making a (no. of ways) to do something series :)
30th Jul 2017, 2:25 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 7
The sep and end function define what you want at the end. sep and end are at default "\n". So we have for count in range(1,11): print(count, end(or you can use sep)='') Note that the end or sep can be anything you want.
30th Jul 2017, 2:11 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 7
@Sk my code is answer
30th Jul 2017, 2:19 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 7
good Night maz!
30th Jul 2017, 2:24 AM
Shadow Windster
Shadow Windster - avatar
+ 7
That's what makes me so (moderately) good at ir. I am hooked to Pythonian simplicity
30th Jul 2017, 2:28 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 7
Okay Sk I will make my code and do homework
30th Jul 2017, 2:29 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 6
I think you can change "[]" brackets into tuple()
30th Jul 2017, 2:11 AM
Shadow Windster
Shadow Windster - avatar
+ 6
@Maz we can do it, lets get fancy: print(", ".join(map(str, range(1,11))))
30th Jul 2017, 2:12 AM
Jakub Stasiak
Jakub Stasiak - avatar
+ 6
@$Vengat yeah! don't need brackets! I'm expecting that!
30th Jul 2017, 2:18 AM
Shadow Windster
Shadow Windster - avatar
+ 6
@maz your code also pretty awesome!
30th Jul 2017, 2:21 AM
Shadow Windster
Shadow Windster - avatar
+ 6
vengat Python is little awesome!
30th Jul 2017, 2:27 AM
Shadow Windster
Shadow Windster - avatar