EDITED
I am working on a conversion table website as my final project. I am using a base unit multiplier to convert one unit to the other. So for example centimeter to yard would look like this.
user_input = amount to be converted
first base unit multiplier = whatever unit chosen to convert from the base unit multiplier, for example it's metres for length
second base unit multiplier = whatever unit chosen to convert to the base unit multiplier
user_input * (base unit multiplier cm to meters) * (base unit multiplier meters to yards)⁻¹
I am running into a snag when I try to multiply the two multipliers with the user_input. I have to change my type list to an int and I have tried three ways. First with row_1 = map(int, row_1), second is number_1 = [ int(x) for x in row_1 ], and third row_1[0]["BUM"]. Neither seem to be working as I have gotten TypeErrors now twice. Is there some very straight forward technique I am overlooking here to make this work? I could add more code if you needed but the final line in the below is where I am getting the error.
Edit #2
I thought the error was with multiplying but it has to do with the parameter substitution. I have use '%s' and a '?' and keep getting the TypeError.
EDIT 3
I have tried to simply input a string, for example (Metre,), ("Metre",), (Metre), and ("Metre") and I am still getting the same error. I have added pictures of my SQL table because maybe something is wrong with it?
amount = request.form.get("amount")
if not amount:
return apology("Enter some numbers")
elif amount.isalpha():
return apology("No letters please")
elif any(c.isalpha() for c in amount):
return apology("I said no letters!")
row_1 = db.execute("SELECT bum FROM conversion WHERE unit = ?", (convert_from,))
row_2 = db.execute("SELECT bum FROM conversion WHERE unit = ?", (convert_to,))
conversion_result = int(amount) * row_1[0]["bum"] * row_2[0]["bum"]**-1
return render_template("length_converted.html", result = conversion_result