[Tutor] string conversion and formatters

Spiffy clams17@yahoo.com
Fri, 7 Dec 2001 11:08:37 -0800 (PST)


Hello! I am just beginning to learn programming and
Python. I am teaching myself using online tutorials
and documentation. Concerning output formatters...as
in "%d", "%s", etc. I know I have seen a listing of
all the types somewhere in the documentation, but for
the life of me I cannot relocate it. Where can I find
it?
 Now for the real question. Here is my first real
program. It is supposed to be a decimal/hex
convertor...
#Decimal/Hex Convertor

def print_options():
    print "Options:"
    print " 'a' decimal to hex"
    print " 'b' hex to decimal"
    print " 'c' print options"
    print " 'd' quit"

choice = "c"
while choice != "d":
    if choice == "a":
        dec = input("Decimal: ")
        print "Hex: %X" % (dec)
    elif choice == "b":
        hex = raw_input("Hex: ")
        print "Decimal: %d" % (hex)
    elif choice != "d":
        print_options()
    choice = raw_input("option: ")
    
If you run this program, it works fine until you try
to convert hex to decimal. Why does this not work? I
have tried using "string.atoi" and some other things,
but no luck. I am stumped. Please, give me some
explanations or hints to point me in the right
direction...I would very much appreciate it!

By the way, I'm using Python2.2 on Windows 98.
Thanks,

   Spiffy






__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com