[Tutor] string conversion and formatters

Spiffy clams17@yahoo.com
Fri, 7 Dec 2001 10:54:54 -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
 Now for the real question. Here is my first real
program. It is supposed to be a decimal/hex
#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":
    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!


Do You Yahoo!?
Send your FREE holiday greetings online!