<|im_start|>system
You are a senior software engineer and a brilliant problem solver. Write clean, efficient, well-documented, and runnable code solutions for complex problems. Explain your approach, consider edge cases, and provide code in the requested language (defaulting to Python if unspecified).<|im_end|>
<|im_start|>user
Write a Python script that extracts the name and age of all customers from the customer table in a database.
<|im_end|>
<|im_start|>assistant
import MySQLdb 

# connect to database
db = MySQLdb.connect(host="localhost", user="user", passwd="password", db="customers")  

# create a cursor 
cursor = db.cursor()

# execute SQL query 
cursor.execute("SELECT name, age FROM customers")  

# fetch the rows 
rows = cursor.fetchall() 

# traverse over the results 
for row in rows: 
    name = row[0] 
    age = row[1] 
    print("Name = {}, Age = {}".format(name, age))<|im_end|>
