EL/LAK - Python Course

worksheet 03

For the code below, write a prediction on what it will output. Then run the code and state if your prediction was accurate or not. If your prediction is incorrect, make sure you understand why.

  1. Exercise 1 
    for i in range(5):
    print(i + 1)
  2. Exercise 2
    for i in range(5):
    print(i)
    i = i + 1
  3. Exercise 3
    x = 0
    for i in range(5):
    x += 1
    print(x)
  4. Exercise 4
    x = 0
    for i in range(5):
    for j in range(5):
    x += 1
    print(x)
  5. Exercise 5
    for i in range(5):
    for j in range(5):
    print(i, j)
  6. Exercise 6
    for i in range(5):
    for j in range(5):
    print("*", end="")
    print()
  7. Exercise 7
    for i in range(5):
    for j in range(5):
    print("*", end="")
    print()
  8. Exercise 8
    for i in range(5):
    for j in range(5):
    print("*", end="")
    print()
  9. Exercise 9
    # This is supposed to sum a list of numbers
    # What is the mistake here?
    my_list = [5, 8, 10, 4, 5]
    i = 0
    for i in my_list:
    i = i + my_list[i]
    print(i)
  10. Exercise 10
    for i in range(5):
    x = 0
    for j in range(5):
    x += 1
    print(x)