Last active
August 29, 2015 14:01
-
-
Save yoshprogrammer/a2f00703a75a89ab21b7 to your computer and use it in GitHub Desktop.
print_triangle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The print_line method is here to help you. | |
# Conceptually, it prints out a row of "count" *'s. Run it yourself to | |
# see how it works. Experiment with different inputs. | |
def print_line(count) | |
for i in 1..count | |
print "*" # This prints a single "*" | |
end | |
print "\n" # This forces the output to the next like, like hitting "return" on the keyboard | |
end | |
# We can call methods we've defined ourselves. In this case, we want | |
# to call the print_line method we've defined to help us print out a square. | |
def print_triangle(height) | |
for i in 1..height | |
print_line(i) # Fill in the blank, here. | |
end | |
end | |
print_triangle(1) | |
print "\n\n\n" # This is here just to make the separation between squares clearer | |
print_triangle(2) | |
print "\n\n\n" # This is here just to make the separation between squares clearer | |
print_triangle(3) | |
print "\n\n\n" # This is here just to make the separation between squares clearer | |
print_triangle(10) | |
# There are no rumble strips this time. It's up to you to decide whether | |
# this is working as intended or not. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment