Я набираю программу для своего класса, проблема сформулирована очень странно, но я поставил свой код для проблемы, я объявляю числа как float правильно? Простой вопрос, но я держу свой разум открытым для других способов делать что-то.Python float numbers и правильное использование
print " This program will calculate the unit price (price per oz) of store items,"
print " you will input the weight in lbs and oz, the name and cost."
item_name = (input("Please enter the name of the item. "))
item_lb_price = float(input("Please enter the price per pound of your item "))
item_lbs = float(input("please enter the pounds of your item. "))
item_oz = float(input("plese enter the ounces of your item. "))
unit_price = item_lb_price/16
total_price = item_lb_price * (item_lbs + item_oz/16)
print "the total price per oz is", unit_price
print "the total price for", item_name, "is a total of", total_price
вы используете Python 2 или 3? –
Наверное, нужно «decimal.Decimal' вместо« float »при работе с деньгами. –
В python мы не объявляем переменные. Там просто не так. То, что вы делаете, - это привязка имен к значениям. –