#πŸ”’ basic problem

114 messages Β· Page 1 of 1 (latest)

muted grail
#
size=int(input("Enter size:"))
symbol=input("Enter symbol:")
for i in range(1,size+1):
    print(symbol*i)
steep orioleBOT
#

@muted grail

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

muted grail
#

my current code gives me a staircase

#

not a pyramid

#

I've also attatched the task requirement that needs to be fullfilled

indigo hound
#

you probably need to center your stars

muted grail
#

yea but how

indigo hound
#

have you used f-strings yet?

muted grail
#

nope we havent been taught that yet

indigo hound
#

are you allowed to use it?

muted grail
#

i dont think so

#

but im open to learning it

indigo hound
#

okay then you need to manually calculate the number of spaces to insert

muted grail
#

hm

indigo hound
#

it should be very simple

muted grail
#

so spaces should be (size/2)-1

#

?

indigo hound
#

on the first row yes

#

where 1 is the number of stars on each row

muted grail
#

then -2 and so on?

#

or is that wrong

indigo hound
#

actually it wouldn't be the number of #'s on each row, it'd be the number of # from the center to the left

#

so it'd just increase by 1 each time

#

1, 2, 3, ...

muted grail
#

uh

indigo hound
#

in other words, i

#

maybe i+1 but you get the idea yeah?

#

there's also str.center but I assume you're not allowed to use that either

muted grail
#
# Task 10: Output a pyramid of size defined by input of the symbol defined through input
size=int(input("Enter size:"))
symbol=input("Enter symbol:")
for i in range(1,size+1):
    print(""*i,2*symbol*i)
#

progress think_LS

indigo hound
#

that's an empty string not a space

#

but closer lol

muted grail
#

oh

#

how do i center them

#

this is what it does with the space

indigo hound
#

remember the calculation for your spaces was size//2 - i

#

not just i

muted grail
#

this might sound stupid

#

but

#

/ gives us a float value and // gives us an ineteger

#

right

indigo hound
#

uhh in this case yes

#

// is floor division, if you use it on two integers it will return an integer

#

otherwise it will return a float that has been floored (rounded towards -infinity)

muted grail
#

whats wrong with my print statement

    print(" "*(size//2)-1,2*symbol*i)
indigo hound
#

2 things, your space calculation doesn't change as you loop (you are not using i in it), and your second part isn't using string multiplication to produce the #'s

muted grail
#

right so i instead of 1

#

and

indigo hound
#

oh

#

symbol is #

muted grail
#

yea user gives us the symbol as input

#

it can be any symbol

indigo hound
#

that's gonna do (2*'#')*i == '##'*i

#

so if that's what you want it works

muted grail
#
size=int(input("Enter size:"))
symbol=input("Enter symbol:")
for i in range(1,size+1):
    print(" "*(size//2)-i,2*symbol*i)
indigo hound
#

oh that's because of operator precedence

#

* happens before - so you have to do the math in one big parenthesis

#

(size//2-i)

#

// has higher precedence than - so you don't need to wrap parens around the division

muted grail
#

bodmas ahahah

#
size=int(input("Enter size:"))
symbol=input("Enter symbol:")
for i in range(1,size+1):
    print(" "*(size//2-i),2*symbol*i)
#

im getting closer.

indigo hound
#

oh size here is the height of your triangle isn't it?

muted grail
#

yep

#

pyramid

#

not triangle

#

our goal is to make a pyramid

#

well triangle

#

same thing

#

LMAO

indigo hound
#

with that formula is should be the width of the last row

muted grail
#

its 2d woopsie

indigo hound
#

same same lol

#

try dropping the //2

muted grail
#

ok

#

this is our goal though

#

the top row still has 2 symbols

indigo hound
#

you just gotta fix your symbol calculation

muted grail
#

mhm

indigo hound
#

right now it's 2*i which gives you 2, 4, 6, ...

#

so how could you change 2*i to give you 1, 3, 5, ...

muted grail
#

can i just -1

#

from the symbol calculation

indigo hound
#

mhm

muted grail
#

but

#

it gives me an error

indigo hound
#

parens again

muted grail
#

i think its the same issue

indigo hound
#

operator precedence

muted grail
#

yeah

#

so i put the paranthesis around

#
    print(" "*(size-i),(2*symbol*i)-1)
#

like this?

#

uhh

indigo hound
#

no

#

all your math involving numbers should be in the parens

#

then multiply that with symbol

muted grail
#

so 2*i-1

#

and then multiply that w symbol

indigo hound
#

yh

muted grail
#

YAY

#

I DID IT

#

WELL WE DID IT

#

THANKS MAN

indigo hound
#

grats lmao

#

np

muted grail
#

ill see you around

#

have a good one :)

#

!close

steep orioleBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.