Cman88 Cman88 - 3 months ago 7
Python Question

I'm not sure what a certain code line does

I was trying to have a program using Python to create a "pyramid" based on a number, n, out of o's and came up with this: ( I would print nn, that would be the lines.)

import time

n = 0
while True:
n += 2 #just another way to show n=n+2
nn = n, "o" #nn would be an amount of o's, based on what #n was
time.sleep(1)
print (nn, str.center(40, " "))


Not sure how to make nn the o's and not sure what line 6 does either. Does anyone know the answer to either question? ( I'm not in a class just programming for fun.)

Answer

This will be the answer to your question

import time

n = 0
while True:
    n += 2
    nn = n * "o"
    time.sleep(1)
    print (nn.center(40, " "))
    if n > 30:
        break

The reason why they have put time.sleep(1) is to make it look like an animation. print (nn, str.center(40, " ")) this must be changed to nn.center(40, " ") as .center is a method of string.