Skip to content
Advertisement

Creating a table with nested loops in python

I’m learning abort nested loops and I’ve gotten an assignment to create a function that takes two integer inputs. Then it should create something like in this image. Only problem is that when I use an odd number for columns it doesnt work.

It has to be an “advanced nested loop” for the assignment to be approved.

JavaScript

createTable(1, 2)

Advertisement

Answer

I have made one iteration of the code which you want. It prints the correct output for even and odd number of rows and columns. It is very similar to the outputs you want. When you provide further clarification for your question, I can provide an updated code.

JavaScript

The output can be visualised below. Hope this solves your query.

enter image description here

Based on the code provided by the question provider, I have edited the code and the following code will work in the same manner as you want it to with nested loops.

JavaScript

Tested for both these cases.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement