Solution: Printing a Diamond Shape

Go over the implementation of printing the diamond shape by dry-running the complex pieces of code.

Courtney's version

Press + to interact
space = " "
space_count = 4
7.times do |row|
if row < 4
space_count -= 1
hash_count = row * 2 + 1
print space * space_count
else
space_count += 1
hash_count = (7 - 1 - row) * 2 + 1
print space * space_count
end
puts '#' * hash_count
end

Explanation

Courtney’s version uses print instead of puts to output the spaces. The print and puts statements are similar except puts outputs a newline character (indicating that the ...

Get hands-on with 1400+ tech skills courses.