Mario
tl;dr
Implement a program that prints out a half-pyramid of a specified height, per the below.
$ python mario.py
Height: 5
#
##
###
####
#####
$ python mario.py
Height: 3
#
##
###
Specification
-
Write, in a file called
mario.py
in~/workspace/pset6/mario/less/
, a program that recreates this half-pyramid using hashes (#
) for blocks, exactly as you did in Problem Set 1, except that your program this time should be written (a) in Python and (b) in CS50 IDE. -
To make things more interesting, first prompt the user for the half-pyramid’s height, a positive integer between
1
and8
, inclusive. -
If the user fails to provide a positive integer no greater than
8
, you should re-prompt for the same again. -
Then, generate (with the help of
print
and one or more loops) the desired half-pyramid. -
Take care to align the bottom-left corner of your half-pyramid with the left-hand edge of your terminal window.
Usage
Your program should behave per the example below. Assume that the underlined text is what some user has typed.
$ python mario.py
Height: 4
#
##
###
####
$ python mario.py
Height: 0
Height: 4
#
##
###
####
$ python mario.py
Height: -5
Height: 4
#
##
###
####
$ python mario.py
Height: -5
Height: five
Height: 40
Height: 24
Height: 4
#
##
###
####
Testing
Correctness
check50 cs50/problems/2019/x/sentimental/mario/less
Style
style50 mario.py
Staff Solution
~cs50/2019/x/pset6/less/mario
How to Submit
Execute the below, logging in with your GitHub username and password when prompted. For security, you’ll see asterisks (*
) instead of the actual characters in your password.
submit50 cs50/problems/2019/x/sentimental/mario/less
You can then go to https://cs50.me/cs50x to view your current scores!
Hints
Try to establish a relationship between (a) the height the user would like the pyramid to be, (b) what row is currently being printed, and (c) how many spaces and how many hashes are in that row. Once you establish the formula, you can translate that to Python!