[Python] I want to change the while statement to def.

Asked 1 years ago, Updated 1 years ago, 127 views

I want to use the while statement below as a def function, what should I do?

i = 0
while True:
     i += 1
     if i > 5: break
     print('*'*i)


And I want to center the result value here.

print("{0:^30}"('*'*i))

If you use it, it's a bit weird. Is there any other way? Contact Us

def python while-statement

2022-09-22 10:16

1 Answers

The number of stars must be 13 57 9 11 to be centralized.

for i in range(1, 11, 2):
    print("{0:^30}".format('*' * i))

              *               
             ***              
            *****             
           *******            
          *********           


2022-09-22 10:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.