My reply is interleaved between your comments.

On Wed, Nov 12, 2014 at 07:33:50PM +0000, niyanax...@gmail.com wrote:

> This is what I have. I am very confused on what to do.

What part is confusing? Try to ask *specific* questions, don't expect us 
to do your homework for you. 


> i = 6
> j = 6

What is the purpose of these two lines of code?


> row = int(input("Row: "))
> column = int(input("Column: "))
> 
> if row == 7 :
>     print("Invalid entry.")
> elif row <= 2 or row > 6 :
>     print("Invalid entry. The row has a range of 2 to 6. Try again.")

Why do you single out 7 as a different error?

Why do you treat 2 as an error when it is supposed to be allowed?


> if column == 7 :
>     print("Invalid entry.")
> elif column <= 2 or column > 6:
>     print("Invalid entry. The column has a range of 2 to 6. Try again.")

The same comments apply for column as for row -- why single out 7, and 
why treat 2 as an error?


> for n in range(row) :
>    print("%10d" % n, end="")

This will print a single row that looks like:

         0          1         2 

and so on. Is that the result that you wanted? If not, what result did 
you want?


> print()
> for n in range(1, row + 1) :
>    print("%10s" % "x ", end="")

This will print a single row that looks like:

         x          x         x 

and so on. Is that the result that you wanted? If not, what result did 
you want?


> print("\n", "    ", "-" * 35)

This will print a single row that looks like:

     -----------------------------------

Is that the result that you wanted? If not, what result did you want?


> for i in range(row):
>     for j in range (column):
>         table[i] [j] = int(table[i] [j])  # convert the string to an integer
>         print(" %3d" % (table[i] [j]), end = " ")
>     print()

Where does table come from? What value or values does it contain?

The question states that you should show the result of i**j (i to the 
power of j, e.g. 2**3 = 8, 2**4 = 16, and so forth) but your code 
doesn't calculate i**j anywhere.

Have a look at this code, and see if it makes sense to you:

for i in range(3):
    print("%4d :::  " % i, end='')
    for j in range(3):
        print("%d plus %d = %d" % (i, j, i+j), end='  ***  ')
    print()


Run the code and see what it prints. Can you see what bit of the code is 
responsible for what part of the output?

Can you change the code to calculate i**j instead of i+j?

Can you change the code to stop printing the "1 plus 1 =" part of each 
cell, and just print the result alone?

Can you change the code to separate the row headers from the cells with 
a single | character instead of three : characters?

Can you change the code to use the values entered by the user instead of 
a fixed 3 x 3 table?

Are there any other changes you need to make to finish the assignment?



-- 
Steven
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to