Week 5: Exercise Solutions

Exercise 5.1

The first version of the program, to print the numbers 1 to n in a row with no gaps between them, looks like:

n = int(input("Please input an integer: "))
for i in range(1,n):

The second version of the program, modified so that n varies in a for loop from 1 to 5, so that you get a triangle of height 5, looks like:

for n in range(1, 6):
    for i in range(1, n+1):
        print(i, end="")

Exercise 5.2

Exercise 5.3

DAYS_OF_WEEK = ["Monday", "Tuesday", "Wednesday",
                "Thursday", "Friday", "Saturday",
for day in DAYS_OF_WEEK:
    print("The first letter of ", day, " is ",
          day[0], ".", sep="")