Jump to content

Python and capital letters


Recommended Posts

I seem to be having trouble figuring out where to use the capitalize function in my code; any help would be great!

 


import MySQLdb


# Connect to the database
try:
    db = MySQLdb.connect(host="xxxxx", db="xxxxx", user="xxxxx", passwd="xxxxx")

except MySQLdb.Error, e:
    print "Error %d: %s" % (e.args[0], e.args[1])
    sys.exit(1)


def mycats(alive=""):
    c = db.cursor()
    if(alive != "a" and alive != "d"):
        c.execute("select name from cats")
    else:
        if(alive == "a"):
            alive = "yes"
        if(alive == "d"):
            alive = "no"
        c.execute("select name from cats where alive = \"%s\"" % (alive))

    
    names = c.fetchall()
    for name in names:
        print "%s" % (name)
        
alive = ""
while alive != "e":
    print "To view cats:\n \
a = alive, d = dead, and all = all.\n \
To exit type in e"
    alive = raw_input(": ")
    if(alive != "a" and alive != "d" and alive != "all" and alive != "e"):
        print""
        print""
        print "Only valid entries are\n a = \"alive\" \n d = \"deceased\" \n all = \"all\" \n e = \"exit\""
        print ""
        continue
    if(alive =="e"):
        print "Goodbye!"
        break
    else:
        print ""
        if(alive == "a"):
            print "My cats that are alive\n"
        elif(alive == "d"):
            print "My cats that are deceased\n"
        else:
            print "This is all of my cats that are alive and dead\n"
        mycats(alive)
        print ""
        print""

Link to comment
https://forums.phpfreaks.com/topic/235293-python-and-capital-letters/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.