Feb-03-2020, 05:15 PM
Hi, I'm new to python so the answer to this may be obvious, but I'm trying to write code to find the cost of electricity used by a device using wattage, the number of hours used, and electricity cost. The code I've written is:
wattage = input("What is the wattage of your device?")
hoursUsed = input("What is the amount of hours used?")
pricePerKWh = 11.76
electricityCost = ((wattage * hoursUsed)/(1000 * pricePerKWh))
print("The cost of electricity is:" + str(electricityCost))
When I run this is recieve:
What is the wattage of your device?3
What is the amount of hours used?3
Traceback (most recent call last):
File "C:/Users/Windows/Documents/lab3.py", line 4, in <module>
electricityCost = ((wattage * hoursUsed)/(1000 * pricePerKWh))
TypeError: can't multiply sequence by non-int of type 'str'
>>>
I can't figure out what I'm doing wrong in the code, again this might be obvious but I'm new to this, thanks in advance.
wattage = input("What is the wattage of your device?")
hoursUsed = input("What is the amount of hours used?")
pricePerKWh = 11.76
electricityCost = ((wattage * hoursUsed)/(1000 * pricePerKWh))
print("The cost of electricity is:" + str(electricityCost))
When I run this is recieve:
What is the wattage of your device?3
What is the amount of hours used?3
Traceback (most recent call last):
File "C:/Users/Windows/Documents/lab3.py", line 4, in <module>
electricityCost = ((wattage * hoursUsed)/(1000 * pricePerKWh))
TypeError: can't multiply sequence by non-int of type 'str'
>>>
I can't figure out what I'm doing wrong in the code, again this might be obvious but I'm new to this, thanks in advance.