Have you heard of the center function 👀 #computerscience #coding #stem #python #apcs

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

The hardest part about programming is remembering all math lessons that you repeat every semester since the 1st Grade.

mousesunset
Автор

rows = 6
for i in range(rows):
print(" "*(rows-i-1), "*"*(2*i+1))

AymanKamel_
Автор

def tree(length):
for lines in range(1, length):
if lines % 2 == 1:

tree(50)

emrahcakl
Автор

This is like taking a calculator to a exam for mental arithmetic. Doing this problem in python is a joke.

robn
Автор

Why would you try solving this in python? These problems are designed for students to get accustomed to loops, if statements and table contents visualisation. This solution defeats the purpose entirely

michaelp
Автор

Me, an intellectual.
print("*")
Print("**")
Print("***")
Print("****")

Daniel
Автор

def tri(n):
for i in range(1, n):
print((n-i)*" ", " *"*i)
print(" "*n, "*")


tri(5)

dheerajkumarroy
Автор

I haven't seen python in so long that I genuinely was thinking that this is pseudo-code

oleksandrdanulchyk
Автор

centre() seems to be doing most of the work. I cant wait to find out what it does behind the scenes. Thanks for bringing it to our attention dawg

KenKikinho
Автор

I learnt this in C and then tried to rewrite it to python. Without the center function. Actually, this function wouldn't enable doing this.

# Block of 5 stars
n = 5
for i in range(n):
for j in range(n):
print("*", end=" ")
print()
print()


# Increasing Triangle Pattern
# *
# * *
# * * *
n = 5
for i in range(n):
for j in range(i+1):
print("*", end=" ")
print()
print()


# Decreasing Triangle Pattern
# * * *
# * *
# *
n = 5
for i in range(n):
for j in range(i, n):
print("*", end=" ")
print()
print()


# Right Sided Triangle 1
# *
# * *
# * * *
n = 5
for i in range(n):
for j in range(i, n):
print(" ", end=" ")
for j in range(i+1):
print("*", end=" ")
print()
print()


# Right Sided Triangle 2
# * * *
# * *
# *
n = 5
for i in range(n):
for j in range(i+1):
print(" ", end=" ")
for j in range(i, n):
print("*", end=" ")
print()
print()


# Hill Pattern
# *
# * * *
# * * * * *
n = 5
for i in range(n):
for j in range(i, n):
print(" ", end=" ")
for j in range(i):
print("*", end=" ")
for j in range(i+1):
print("*", end=" ")
print()
print()


# Reverse Hill Pattern
# * * * * *
# * * *
# *
n = 5
for i in range(n):
for j in range(i+1):
print(" ", end=" ")
for j in range(i, n-1):
print("*", end=" ")
for j in range(i, n):
print("*", end=" ")
print()
print()


# Diamond Pattern
# *
# * * *
# * * * * *
# * * *
# *
n = 5
for i in range(n-1): # (n-1)
for j in range(i, n):
print(" ", end=" ")
for j in range(i):
print("*", end=" ")
for j in range(i+1):
print("*", end=" ")
print()
for i in range(n):
for j in range(i+1):
print(" ", end=" ")
for j in range(i, n-1):
print("*", end=" ")
for j in range(i, n):
print("*", end=" ")
print()
print()

elevendarter
Автор

I am absolutely proud of having done this in Java with " " and endless amount of for loops, very proud.

veddy
Автор

As a C/C++ developer i can say that's really hurts my heart, i mean what is even this center funct (u have to make it)😢😢

BonadaganiLtmani-kvbt
Автор

def tree(height):

c = 1
for i in range(height, 0, -1):
print(' '*i, end=f'{"*"*c}')
c = c+2

print()

height = int(input("Tree height:"))
tree(height)

AnurupaKarmakar-eslc
Автор

f-strings are more pythonic

def tree(height):
width = 2 * height - 1
for i in range(1, height + 1):
print(f"{'*' * (2 * i - 1):^width}")
print(f"{'*':^width}")

aerophage
Автор

literally just add 2 to i and print that many times

Print(*)
For(int i = 1; i < count; i++)
{
For(int j = 0; j < i + 2; j++)
{
Print(*)
}
Print(/n)
}

bradjones
Автор

def tree(rows):
for i in range(1, rows*2, 2)], sep="\n")
tree(10)

RyzerAfter
Автор

def tree (height):
for i in range(height):
print((height - i) * " " + (2 * i + 1) * "*")
print( height * " " + "*")


tree(6)

LightMouradYagami
Автор

def tree(height):
n=(height*2)-1
for i in range(1, n+1, 2):
print(((n-i)//2)*' '+i*'*'+((n-i)//2)*' ')
tree(10)

makkasatya
Автор

You said it in a way the center function makes it harder to solve, when it’s the opposite xd

popipopi
Автор

ls=['*'*i for i in range(1, 12, 2)]
for row in ls:
print(row.center(22))
print('*'.center(22))

protheeslameslam