aazzzz444
aazzzz444

Reputation: 9

How do I multiply a sequence with a non-int type of float?

import openpyxl as xl
wb = xl.load_workbook('transactions.xlsx')
sheet = wb['Sheet1']
cell = sheet['a1']
cell = sheet.cell(1, 1)

for row in range(1, sheet.max_row + 1):
    cell = sheet.cell(row, 3)
    corrected_price = cell.value * 0.9
    corrected_price_cell = sheet.cell(row, 4)
    corrected_price_cell.value = corrected_price

wb.save('transactions2.xlsx')


followed a tutorial online by mosh and did the exact same thing for automation with python and for some reason mine doesnt work on line 9 cause it says its a multiplication issue involving a float. heres the traceback

Traceback (most recent call last): File "/Users/lukapavicic/Desktop/py/pythonProject/app.py", line 9, in corrected_price = cell.value * 0.9 ~~~~~~~~~~~^~~~~ TypeError: can't multiply sequence by non-int of type 'float'

Process finished with exit code 1

Upvotes: 0

Views: 31

Answers (1)

Sanket Wagh
Sanket Wagh

Reputation: 166

Can you check the type of cell.value if it is a sequence like list, then you cannot mulitply it by float. if it is a string you can probable use casting it to float(cell.value) or int(cell.value)

Upvotes: 0

Related Questions