0

Python, i want only advice to do it alone,i tried with while but i got one column

Input a number for example 4: And output is : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

18th Sep 2017, 8:11 PM
Abd Allah Abd Alkader
Abd Allah Abd Alkader - avatar
12 Respuestas
0
i think you have to do like i did but with a string so you dont get the [ , , ,]
18th Sep 2017, 8:40 PM
Zit Zittoun
Zit Zittoun - avatar
+ 2
if you want to keep it simple, use a for loop and a counter. each iteration of the for loop, after you print the next number, increase the counter +1.. each run of the loop, if the counter is > the input number, do a print("\n") to start a new line and reset the counter to 1 num=input count=1 for to the range of num*num if count is > num then print(\n) else print the iteration with an end=''
18th Sep 2017, 8:37 PM
LordHill
LordHill - avatar
+ 1
You can use 2 for loops, one nested in the other, that uses the number input in the range to end each for loop.
18th Sep 2017, 8:27 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Would you like some pseudo code? You said you want to do it yourself, so I don't want to give you too much info.
18th Sep 2017, 8:30 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
create a variable to get the input from the user print a new line for aesthetics in the playground create a number variable and set it to an initial value (1) create an outer for loop that goes from _ to range of input variable create an nested for loop that goes from _ to range of input variable print the current value of the number variable and use a space as the end char for print increment the number variable by 1 print a new line
18th Sep 2017, 8:39 PM
ChaoticDawg
ChaoticDawg - avatar
0
4 is the number of lines or the number of number per line? or both ?
18th Sep 2017, 8:19 PM
Zit Zittoun
Zit Zittoun - avatar
0
Both
18th Sep 2017, 8:20 PM
Abd Allah Abd Alkader
Abd Allah Abd Alkader - avatar
0
So if the number 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
18th Sep 2017, 8:21 PM
Abd Allah Abd Alkader
Abd Allah Abd Alkader - avatar
0
Which loop then?
18th Sep 2017, 8:26 PM
Abd Allah Abd Alkader
Abd Allah Abd Alkader - avatar
0
I tried with while and for
18th Sep 2017, 8:32 PM
Abd Allah Abd Alkader
Abd Allah Abd Alkader - avatar
18th Sep 2017, 8:37 PM
Zit Zittoun
Zit Zittoun - avatar
0
Oh thanks now i will try it
18th Sep 2017, 8:41 PM
Abd Allah Abd Alkader
Abd Allah Abd Alkader - avatar