I'm trying to print variable c but whenever I do I get "Cost of electricity: $□". But if I print the variable c with print(c) I get "6.122448979591836". So it must be something about substituting the variable in with the % right? I'm using Python 3.5.2 btw. Also I need the number displayed to be 6.12 and using round(c, 2) does nothing. Is it because it's not an int?
# print #100 Cost of Electricity
print("#100 Cost of Electricity")
# get wattage
w = int(input("Enter wattage: "))
# get hours used
h = int(input("Enter number of hours used: "))
# get price per/kWh
p = float(input("Enter price per kWh in cents: "))
# calculate cost
c = w*h/(1000*p)
# print price
print("Cost of electricity: $%c" % int(c))
print("Cost of electricity: $%.2f" % c)
The 'f' flag is for floating point format. The '.2' says print 2 digits after the decimal.