...

/

Solutions: Printing Shapes Exercises

Solutions: Printing Shapes Exercises

Use the knowledge gained in this chapter to solve the exercise questions.

Print a rhombus

Press + to interact
hashtag = "#"
space = " "
width.times do |row|
space_count = width - row - 1
print space * space_count
puts hashtag * width
end

Explanation

  • Line 4: We subtracted the current row’s value from the total number of rows to calculate spaces. Note that we also subtracted an additional 1 ...