15,789,698 members
0.00/5 (No votes)
See more:
```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.
Posted
Updated 15-Jul-22 19:22pm

## Solution 1

Quote:
I am very confused with this

Have a talk with your teacher, we can't teach you programming in the scope of this little textbox.

You claim no specific problem, you show no work, no try of anything, the help you want is us doing your homework. It will not happen.
Here, we help you fix your work, but you need to have done something.

The principle of homework is that you learn by trial and error, it we do your homework, it defeat the purpose.
Do you think Usain Bolt asked someone to train for him when he was a beginner ?

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.

Advice:
Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

<
27.3. pdb — The Python Debugger — Python 3.6.1 documentation[^]
Debugging in Python | Python Conquers The Universe[^]
pdb – Interactive Debugger - Python Module of the Week[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.

v2

## Solution 2

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

Just posting your homework and saying "I can't do this" isn't going to get you anyuwhere!

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 Graeme_Grant 250 Rick York 120 Maciej Los 90 Dave Kreskowiak 50 CPallini 50
 Richard MacCutchan 1,490 Dave Kreskowiak 1,400 Maciej Los 815 Richard Deeming 743 CPallini 700

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900