Python Beginner Line Wrap Output Questions

Asked 2 years ago, Updated 2 years ago, 15 views

Hello, I'm a beginner who started Python this week.
I was solving the problem, and I had a difficulty, so I left a question here.
First of all,

Q. When x = 30 is entered

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 26 27 28 29 30

It's a problem that has to appear like this.

The code I made is

x = int (input ("please enter a number")

for i in range(30) :
    if i <= 9:
        print(i+1,end="")
    elif i <=19 :
        print(i+1,end="")
    else :
        print(i+1,end="")

It's this. If you do this,

123456789101112131415161718192021222324252627282930

It comes out like this.

I'd like to ask you how to print out the new line.

python

2022-09-20 19:20

1 Answers

First of all, you can run print() (without a factor value) to insert a line change. Alternatively, you can put \n at the end, such as print ("what you originally want to type\n"). However, if you only know this, you still can't solve the problem.

The problem is probably something like this.

So let's take a different approach. When an integer is entered:

Try it!

PS. There's also this kind of approach.

if i % 10 == 0 :
    print()


2022-09-20 19:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.