Reputation: 25
So I am trying to multiply a number from a text file to a variable called quantity
which is also a number but for example 3x5
, it would output 33333
, but I need 15, how do I fix this?
if GTIN=='86947367':
with open("read_it.txt") as fp:
next(fp)
next(fp)
total1=quantity*int(next(fp))
print(total1)
output:33333
Upvotes: 0
Views: 685
Reputation: 2124
Well, obviously, your quantity
is as string '3'
- and this gets multiplied by 5, giving '33333'
. You need one more int()
to convert the '3'
to 3
:)
Upvotes: 1