There are 7 steps/challenges to this assignment. Complete all steps for full credit.
Submit your code together with program output to the text submission window.
1. Start a new program with the code that follows. Notice how the for loop that uses variable x as a counter encloses a second for loop that uses variable y as a counter. One way to visualize this code is to consider the x loop counting rows while the y loop is counting columns in a grid.
print("x, y")
for x in range(1, 4): # outer loop
for y in range(1, 5): # inner loop
print(x, ",", y, end=" ")
print()
print()
# Output
x, y
1 , 1 1 , 2 1 , 3 1 , 4
2 , 1 2 , 2 2 , 3 2 , 4
3 , 1 3 , 2 3 , 3 3 , 4
2. Modify the code above (part 1). Add an additional nested loop structure (see below) to create the output that follows:
print("x, y")
for x in range(1, 4): # outer loop
for y in range(1, 5): # inner loop
print(x, ",", y, end=" ")
print()
print()
# add additional code here
# Output
x, y
1 , 1 1 , 2 1 , 3 1 , 4
2 , 1 2 , 2 2 , 3 2 , 4
3 , 1 3 , 2 3 , 3 3 , 4
x: 1 y: 1 2 3 4
x: 2 y: 1 2 3 4
x: 3 y: 1 2 3 4
3. Challenge: Modify your code from above (part 2).
Add additional code to produce the following output:
# Output
x, y
1 , 1 1 , 2 1 , 3 1 , 4
2 , 1 2 , 2 2 , 3 2 , 4
3 , 1 3 , 2 3 , 3 3 , 4
x: 1 y: 1 2 3 4
x: 2 y: 1 2 3 4
x: 3 y: 1 2 3 4
x: 1 y: 1
x: 2 y: 1 2
x: 3 y: 1 2 3
x: 4 y: 1 2 3 4
x: 5 y: 1 2 3 4 5
4. Challenge: Modify your code from above (part 3).
Add additional code to produce the following output:
# Output
x, y
1 , 1 1 , 2 1 , 3 1 , 4
2 , 1 2 , 2 2 , 3 2 , 4
3 , 1 3 , 2 3 , 3 3 , 4
x: 1 y: 1 2 3 4
x: 2 y: 1 2 3 4
x: 3 y: 1 2 3 4
x: 1 y: 1
x: 2 y: 1 2
x: 3 y: 1 2 3
x: 4 y: 1 2 3 4
x: 5 y: 1 2 3 4 5
x: 1 y: 1 2 3 4 5
x: 2 y: 1 2 3 4
x: 3 y: 1 2 3
x: 4 y: 1 2
x: 5 y: 1
5. Challenge: Modify your code from above (part 4).
Add additional code to produce the following output:
# Output
x, y
1 , 1 1 , 2 1 , 3 1 , 4
2 , 1 2 , 2 2 , 3 2 , 4
3 , 1 3 , 2 3 , 3 3 , 4
x: 1 y: 1 2 3 4
x: 2 y: 1 2 3 4
x: 3 y: 1 2 3 4
x: 1 y: 1
x: 2 y: 1 2
x: 3 y: 1 2 3
x: 4 y: 1 2 3 4
x: 5 y: 1 2 3 4 5
x: 1 y: 1 2 3 4 5
x: 2 y: 1 2 3 4
x: 3 y: 1 2 3
x: 4 y: 1 2
x: 5 y: 1
x: 1 y: 1 2 3 4 5
x: 2 y: 2 3 4 5
x: 3 y: 3 4 5
x: 4 y: 4 5
x: 5 y: 5
6. Challenge: Modify your code from above (part 5).
Add additional code to produce the following output:
# Output
x, y
1 , 1 1 , 2 1 , 3 1 , 4
2 , 1 2 , 2 2 , 3 2 , 4
3 , 1 3 , 2 3 , 3 3 , 4
x: 1 y: 1 2 3 4
x: 2 y: 1 2 3 4
x: 3 y: 1 2 3 4
x: 1 y: 1
x: 2 y: 1 2
x: 3 y: 1 2 3
x: 4 y: 1 2 3 4
x: 5 y: 1 2 3 4 5
x: 1 y: 1 2 3 4 5
x: 2 y: 1 2 3 4
x: 3 y: 1 2 3
x: 4 y: 1 2
x: 5 y: 1
x: 1 y: 1 2 3 4 5
x: 2 y: 2 3 4 5
x: 3 y: 3 4 5
x: 4 y: 4 5
x: 5 y: 5
x: 1 y: 1 2 3 4 5
x: 2 y: 2 3 4 5
x: 3 y: 3 4 5
x: 4 y: 4 5
x: 5 y: 5
7. Challenge: Modify your code from above (part 6).
Add additional code to produce the following output:
# Output
x, y
1 , 1 1 , 2 1 , 3 1 , 4
2 , 1 2 , 2 2 , 3 2 , 4
3 , 1 3 , 2 3 , 3 3 , 4
x: 1 y: 1 2 3 4
x: 2 y: 1 2 3 4
x: 3 y: 1 2 3 4
x: 1 y: 1
x: 2 y: 1 2
x: 3 y: 1 2 3
x: 4 y: 1 2 3 4
x: 5 y: 1 2 3 4 5
x: 1 y: 1 2 3 4 5
x: 2 y: 1 2 3 4
x: 3 y: 1 2 3
x: 4 y: 1 2
x: 5 y: 1
x: 1 y: 1 2 3 4 5
x: 2 y: 2 3 4 5
x: 3 y: 3 4 5
x: 4 y: 4 5
x: 5 y: 5
x: 1 y: 1 2 3 4 5
x: 2 y: 2 3 4 5
x: 3 y: 3 4 5
x: 4 y: 4 5
x: 5 y: 5
x: 1 y: 5
x: 2 y: 4 5
x: 3 y: 3 4 5
x: 4 y: 2 3 4 5
x: 5 y: 1 2 3 4 5
What I have tried:
I am very confused with this, any help would be greatly appreciated.