Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.