Re: [Tutor] Creating Table

2014-11-12 Thread Steven D'Aprano
My reply is interleaved between your comments.


On Wed, Nov 12, 2014 at 07:33:50PM +, 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


Re: [Tutor] Creating Table

2014-11-12 Thread Danny Yoo
On Wed, Nov 12, 2014 at 11:33 AM,   wrote:
> Create a table based on two user inputs.  Have the user enter two integers
> between 2 and 6.  Validate the user inputs are in the proper range as they
> are entered.  The first integer represents the number of rows in the table.
> The second integer represents the number of columns.
> Create the table by storing the value (i **j) in each cell in the table.
> Print the Power table with a column header separated from the table by a
> line of underscores (“_”) and a row header that lists the row number, a “|”
> and the row of data.
>
> This is what I have. I am very confused on what to do.

[code cut]

Hi Niyana,

We need to pinpoint where you're getting confused.  I get confused for
all sorts of different reasons myself, so forgive me if this sounds
really basic.   :P

I will ignore your code entirely for the moment.

Do you know what the output is supposed to look like for small inputs?

  * What should the program output look like when rows=2 and columns=2?
  * What should the program output look like when rows=2 and columns=3?
  * What should the program output look like when rows=3 and columns=2?

The inputs are small enough that you should be able to write what you
know the program should do, even before trying to teach the computer
how to do it.

Let's make sure we understand the problem we're trying to solve before
rushing to code it.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor