Python printed output from IF statement to SQL column

Viewed 34

Is it possible that a printed output from an if statement can be placed in a MySQL column? That column num insert the value: "you have to pay 5% taxes" or "you not have to pay taxes".

num = 10
if 5 <= num <= 15:
    print ("you have to pay 5% taxes")
else:
    print ("you not have to pay taxes")

cursor.execute(""
SELECT *, FROM Customers
""")
1 Answers

Assuming you are using MySQL database with python.

num    = 15
string = "you have to pay 5% taxes" if 5<=n<=15 else "you not have to pay taxes"

sql = "INSERT INTO yourtable (col1, col2) VALUES (%s, %s)"
val = (num, string)
mycursor.execute(sql, val)
print(string)
Related