[Tutor] number conversion problem (was: Re: [no subject])
Lance E Sloan
lsloan-000002 at umich.edu
Tue Jun 8 17:17:15 EDT 2004
--On Tuesday, June 8, 2004 4:45 PM -0400 Dragonfirebane at aol.com wrote:
> the full code as is is below (not working). as of right now, i'm
> oncentrating only on the text function since the number converter works
> fine. the reason i'm using if and not for is that using for creates a
> loop where the program prints the converted number based on the number of
> characters in the original number (1100 1100) or
> something of the sort for 12, whereas 'if' prints the same number (1100)
> once, due to the [print binary[int(original) - 1]] command.
OK. Then I think we're back to the problem being that you are referencing
"char" before you ever assign any value to it. The error I get is:
Please enter numbers or text to be converted. 1234
Traceback (most recent call last):
File "multivert.py", line 33, in ?
if char in number:
NameError: name 'char' is not defined
What do you expect the variable "char" to contain? A single character of
the user's input string, one character at a time until you reach the end of
If so, you're going to need a line like this somewhere just before you
for char in original:
I've not checked this, but it would probably go just before your "if char
in number" statement.
Also, I don't know the details of the problem you're trying to solve, but
there are more mathematical ways of converting numbers from one base to
another that would not require you to include long lists of all the
possible conversions in your program.
Lance E Sloan, Systems Research Programmer III
U-M WATS: Web Applications, Technologies, and Solutions
Full-service web and database design, development, and hosting.
http://www.itcs.umich.edu/wats/ - "Putting U on the Web"
More information about the Tutor