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
12 Respuestas
0
i think you have to do like i did but with a string so you dont get the [ , , ,]
+ 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=''
+ 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.
+ 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.
+ 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
0
4 is the number of lines or the number of number per line? or both ?
0
Both
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
0
Which loop then?
0
I tried with while and for
0
Oh thanks now i will try it