My 12 year old is leaing python scripting. He is writing a very simple code to calculate the discount on a article. Following is the code and it throws the exception on the 3rd line in the code. The exception is:
Traceback (most recent call last): File "C:/Users/basam/AppData/Local/Programs/Python/Python35/discounts.py", line 3, in discount=0.1*price TypeError: can't multiply sequence by non-int of type 'float'
price=input('how much is your item?')
if int(price) <= 10:
discount=0.1*price
The key is int(price). The input command retus a string which is stored in the variable price.
In the second line, price is converted to a number by the call int(price), but that result is not stored anywhere. It is used for the comparison and then discarded. So when you go to multiply in the third line, you're trying to multiply a number times a string.