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""