-1

Trying to build pyramids in Python, something similar to the following

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

Please note there are TWO stars on line 4. Currently all I have is this:

for stars in range(4,0,-1):
    print("*"*stars)

Which yields the following:

****
***
**
*

Please advise.

  • 2
    ["Can Someone Help Me?" is not a valid SO question)[https://meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-actual-question). This usually suggests that what you need is half an hour with a local tutor or walk through a tutorial, rather than Stack Overflow. – Prune Jun 05 '17 at 23:42
  • @user3717717, your question regarding if it written as a Var or in a text file, in those contexts, probably written as a variable `stars` since the characters are an explicit string `"*"` – chickity china chinese chicken Jun 05 '17 at 23:47
  • Thoughts! You should write two functions: `stars_on_left` and `stars_on_right`. They should take a line number and a total number of star rows, and return how many stars should be on each side of the row. For instance `stars_on_left(row=0, total_rows=4)` should give 4. `stars_on_right(row=4, total_rows=4)` should give 1. You should be able to use that and the knowledge that each row should be 7 characters wide to do what you need to do. – Adam Smith Jun 05 '17 at 23:50
  • my solution https://repl.it/I74q/0 – yhoyo Jun 06 '17 at 00:15

1 Answers1

0

Super ugly, adopted from this answer Python: Print a triangular pattern of asterisks.

for stars in range(4,1,-1):
    print("*" * stars)

print("*     *")

for g in range (5,2,-1):
    print(g * ' ' + (7-g) * '*')

Disclaimer: I don't yet know the technicalities why it works, but I would happily dissect it and explain why it does if needed! :)

  • Works wonders thanks. Is there any way to remove the string "* *" so that the solution does not rely on strings? Anyhow fantastic solution. – Joel Foucault Jun 06 '17 at 00:09
  • Glad to help, I'm sure there is, I agree with you, I thought that was a weak-hack workaround, I'll work with it a bit more and update if I can get that part out of the solution. – chickity china chinese chicken Jun 06 '17 at 00:11
  • https://repl.it/I74q/0 – yhoyo Jun 06 '17 at 00:17
  • How is this a duplicate, the two figures intersect? – Joel Foucault Jun 06 '17 at 00:19
  • The moderators probably didn't want the question to be answered, so they used that link I included as a reason to close the question ¯\\_(ツ)_/¯ . Anyhow, I think yhoyo's answer is more what you were looking for. @yhoyo – chickity china chinese chicken Jun 06 '17 at 00:21
  • actually if you run yhoyo's code with `piramid (4, 0, -1)`, you should get the correct output. – chickity china chinese chicken Jun 06 '17 at 00:29
  • Just spent an hour making a new creative solution to the problem and the mods lock it, fantastic. Leaving the question open can generate new ideas to look at the same problem which someone else may find useful. – syntaxError Jun 06 '17 at 01:04
  • @rosh, agreed, I expected they'd do that, that's why I threw up this hideous answer before they locked it, feel free to link to a repl.it of your code like yhoyo did if you want to share it if someone may find it useful. Or you could post your own Question and Answer it with your code. (quickly before it also may get locked!) – chickity china chinese chicken Jun 06 '17 at 01:09