It's a question about Python beginner for Moon

Asked 2 years ago, Updated 2 years ago, 84 views

//for i in range(5):
    for j in range(i+1):
        print('*',end='')
    print("")
    for i in range(5):
        for j in range(5-i):
            print('*',end='')
        print("")

When I do this, it becomes double cloth, so the shape I want doesn't come out.But there's for

//for i in range(5):
    for j in range(i+1):
        print('*',end='')
    print("")
  for i in range(5):
    for j in range(5-i):
        print('*',end='')
    print("")

I don't know why, but the error Unindent does not match any outer indication level appears.Is there any way to start a new for statement?How can I execute the for statement above first and then execute the for statement below separately?

python for error

2022-09-22 19:46

1 Answers

I tried to run it with your second code, but the error you mentioned didn't occur. Please check if there are any typos.

for i in range(5):
    for j in range(i+1):
        print('*', end='')
    print("")
for i in range(5):
    for j in range(5-i):
        print('*', end='')
    print("")

If there is an error while checking the result with the 'Execute Code' button on the hash code site, When you write code, check if you wrote python3 in the programming language.

Try running code with Faicham or another interpreter and it will work well.


2022-09-22 19:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.