[Tutor] Require help for a script

Alan Gauld alan.gauld at yahoo.co.uk
Tue Sep 19 04:54:18 EDT 2017


On 19/09/17 08:48, Clara Chua wrote:
> Hi Python tutor, I require help for a script that asks user for number of
> rows, r and number of columns c, and generates a r x c matrix with the
> following values:

What help do you need?
Which part of the above do you not know how to do?

Can you ask the user for two numbers and store them
in two variables?

It says generate a matrix, I'm guessing that's
where the numpy stuff comes in although a standard
Python list would be just as effective in this case.
In either case can you define a new two dimensional
data structure using the sizes read previously?

> - The value of each element in the first row is the number of the column

Do you know how to populate the first row?

> - The value of each element in the first column is the number of the row

Do you know how to populate the first column (or first
element of each row)?

> - The rest of the elements each has a value equal to the sum of the element
> above it and the element to the left.

Do you know how to iterate over each cell in your matrix,
starting with the second row?

For a given cell do you know how to read the value above?
For a given cell do you know how to read the value left?

Do you know how to sum two values and store the result
in the current cell?

> Example of such matrix if a user inputs r=4 and c=5
> 
> 1    2     3     4     5
> 2    4     7    11   16
...

Tell us which part of the problem you are stuck with.
Show us the code you have tried and any error
messages (in full). Then we can give you more focused
help.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list