Input 5 output 12345 in python
I am new to python and I was practicing my coding skills with Hacker rank. I came across a question where I have to print numbers in a series one after another without adding any new line or white space in between them and most important is I cannot use the string method to get desired output. Show For example if input is
then output should be
How can do it without string? Please guide me... Thanks in advance
asked Dec 10, 2016 at 16:12
1 You can use
answered Dec 10, 2016 at 16:21
Yevhen KuzmovychYevhen Kuzmovych 8,0355 gold badges24 silver badges41 bronze badges 4 You may create a custom function using
Sample run:
This way you will get the actual value and you won't be just printing it on the console answered Dec 10, 2016 at 16:17
Moinuddin QuadriMoinuddin Quadri 44.6k12 gold badges92 silver badges118 bronze badges 2 for statement below takes elements starting from 1 to n.
printing without new line requires and addition in print command.
answered Feb 15, 2021 at 11:09
timgeb 74.5k20 gold badges114 silver badges139 bronze badges answered Dec 8, 2018 at 13:12
2 The
following copy integer values to array
answered Mar 11, 2021 at 18:12
2 If you want to print n natural number without using string then you can try this code:
simple input: 5
Gino Mempin 20.8k24 gold badges84 silver badges111 bronze badges answered Dec 2, 2019 at 21:46
0 How do I print 12345 in Python?how to print 12345 in one row without using string. +8. print(*(n for n in range(1,6)), sep="") or just print(12345) as suggested by Diego. ... . +6. Language - Python This might be cheating but try it: num = 12345; print(num) And next time please specify the programming language. ... . +5. ... . +3. ... . +2. ... . +2. ... . +1. ... . How do you print 5 numbers in Python?To print 1 to 50, you need to pass n+1 for eg, 1 to 51 in range function, its (i=1;i<51,i++) in C alike syntax.. print comma if you want between every digits.. to print line break for every 5, you can just use current if i%5==0: but print blank line, instead of i.. What does output () do in Python?Python Output Using print() function
We use the print() function to output data to the standard output device (screen). We can also output data to a file, but this will be discussed later. An example of its use is given below.
How do I output in Python?The basic way to do output is the print statement. To end the printed line with a newline, add a print statement without any objects. This will print to any object that implements write(), which includes file objects.
|