I understand most things that we are going over, but I am making a point to pay attention because of the midterm. I almost always get 100% on programming assignments, labs, and homework, but I typically don’t do very well on programming quizzes. I am not sure that they are representative of my knowledge in the class. I don’t know why this is the case, but maybe I just make stupid mistakes? I need to start double checking all of the answers at the end of taking my quiz, even if I am confident in the material. I am going to speak with my professors about it today.
I came up with a clever way to print an equilateral triangle.
My professor wrote the code, but in class, I came up with the i*2 -1
for the number of stars and height - i
for the number of spaces. I was pretty proud of figuring that out.
# loop to create an equilateral triangle.
'''
* #1 #4
*** #3 #3
***** #5 #2
******* #7 #1
********* #9 stars #0 spaces
# Number of starts: i*2 - 1
1 1*2 - 1 == 2 - 1 = 1
2 2*2 - 1 == 4 - 1 = 3
3 3*2 - 1 == 6 - 1 = 5
4 4*2 - 1 == 8 - 1 = 7
height = 5 5*2 - 1 == 10 - 1 = 9
# Number of spaces: height - i
i=1 5 - 1 = 4
i=2 5 - 2 = 3
, i=3 5 - 3 = 2
height = 5, i=4 5 - 4 = 1
height = 5, i=5 5 - 5 = 0
'''
height = int(input("How tall: "))
for i in range(1, height+1):
print(" "*(height-i) + "*"*(i*2 - 1))