Mario
Problem to Solve
In a file called mario.py
in a folder called sentimental-mario-less
, write a program that recreates a half-pyramid using hashes (#
) for blocks, exactly as you did in Problem Set 1. Your program this time should be written in Python!
Demo
Specification
- To make things more interesting, first prompt the user with
get_int
for the half-pyramid’s height, a positive integer between1
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.
How to Test
While check50
is available for this problem, you’re encouraged to first test your code on your own for each of the following.
- Run your program as
python mario.py
and wait for a prompt for input. Type in-1
and press enter. Your program should reject this input as invalid, as by re-prompting the user to type in another number. - Run your program as
python mario.py
and wait for a prompt for input. Type in0
and press enter. Your program should reject this input as invalid, as by re-prompting the user to type in another number. - Run your program as
python mario.py
and wait for a prompt for input. Type in1
and press enter. Your program should generate the below output. Be sure that the pyramid is aligned to the bottom-left corner of your terminal, and that there are no extra spaces at the end of each line.
#
- Run your program as
python mario.py
and wait for a prompt for input. Type in2
and press enter. Your program should generate the below output. Be sure that the pyramid is aligned to the bottom-left corner of your terminal, and that there are no extra spaces at the end of each line.
#
##
- Run your program as
python mario.py
and wait for a prompt for input. Type in8
and press enter. Your program should generate the below output. Be sure that the pyramid is aligned to the bottom-left corner of your terminal, and that there are no extra spaces at the end of each line.
#
##
###
####
#####
######
#######
########
- Run your program as
python mario.py
and wait for a prompt for input. Type in9
and press enter. Your program should reject this input as invalid, as by re-prompting the user to type in another number. Then, type in2
and press enter. Your program should generate the below output. Be sure that the pyramid is aligned to the bottom-left corner of your terminal, and that there are no extra spaces at the end of each line.
#
##
- Run your program as
python mario.py
and wait for a prompt for input. Type infoo
and press enter. Your program should reject this input as invalid, as by re-prompting the user to type in another number. - Run your program as
python mario.py
and wait for a prompt for input. Do not type anything, and press enter. Your program should reject this input as invalid, as by re-prompting the user to type in another number.
Correctness
check50 cs50/problems/2024/spring/sentimental/mario/less
Style
style50 mario.py
How to Submit
Per Step 4 below, after you submit, be sure to check your autograder results. If you see SUBMISSION ERROR: missing files (0.0/1.0)
, MissingFilesError
, or the like, it means your file was not named exactly as prescribed (or you uploaded it to the wrong problem).
Correctness in submissions entails everything from reading the specification, writing code that is compliant with it, and submitting files with the correct name. If you see this error, you should resubmit right away, making sure your submission is fully compliant with the specification. The staff will not adjust your filenames for you after the fact!
- Download your
mario.py
file by control-clicking or right-clicking on the file in your codespace’s file browser and choosing Download. - Go to CS50’s Gradescope page.
- Click Problem Set 6: Sentimental (Mario Less).
- Drag and drop your
mario.py
file to the area that says Drag & Drop. Be sure it has that exact filename! If you upload a file with a different name, the autograder likely will fail when trying to run it. Ensuring you have uploaded files with the correct filename is your responsibility! - Click Upload.
You should see a message that says “Problem Set 6: Sentimental (Mario Less) submitted successfully!”