Monday, February 28, 2011

Feb 28

Recapping from last week, when i tried to to re-put in the program for print_multiples. I then made an error but when I enter the program I got no error message, so what I did from there was put into the python terminal was print_multiples(3). After I did this, surprisingly I didn't get a error message, I got a continuously flowing 3 table. The program again was:
 def print_multiples(n):
...     i = 1
...     while i <= 6:
...             print m * i, '\t',
...             i += 1
...     print
...
>>>

My modified program of this program was:
>>> def print_multples(n):
...     i = 1
...     while i <= 6:
...             print n * i, '\t',
...     i += 1
... 
>>> 

The error was where i += 1 was suppose to be found right under print n * i, '\t', but instead I missed typed. I tried figuring out a way to allow this program to stop generating the number 3 but so far I've been unable to find a way to get the program to stop the generation. 
def print_mult_table():
i = 1
while i <= 6:
print_multiples(i)
i += 1

The book told me to wrap this program into the program I first created. So the overall program is:
def print_mult_table():
i = 1
while i <= 6:
print_multiples(i)
i += 1
def print_multiples(n):
i = 1
while i <= 6:
print n * i, '\t', 
i += 1
i = 1
while i <= 6:
print_multiples(i)
i += 1

After I applied this program to the terminal I got:
File "print_multiples.py", line 13, in print_multiples
    print_multiples(i)

I got this error a good 50 times in the terminal. I really don't get what the results of this program means. I really don't know if this program has a error or that the program is suppose to out put File "print_multiples.py", line 13, in print_multiples
   print_multiples(i)


2 comments:

  1. I'm unable to help with the error here because you did not include the error in your post. The:

    File "print_multiples.py", line 13, in print_multiples
    print_multiples(i)

    is telling you *where* the error is, not *what* the error is. The "what" is reported on the last line of the message, below the listing of where it occured.

    For example:

    >>> 4 + "this"
    Traceback (most recent call last):
    File "", line 1, in
    TypeError: unsupported operand type(s) for +: 'int' and 'str'

    You gave me the equivalent of:

    "File "", line 1, in

    what we need is what comes next:

    TypeError: unsupported operand type(s) for +: 'int' and 'str'

    which is what tells us what went wrong.

    ReplyDelete
  2. Sorry about that, you can't use greater than or less than signs in comments, since they get interpreted as the start of html tags.

    Let's talk about this on Monday.

    ReplyDelete