想出一个python代码来解决以下问题

想出一个python代码来解决以下问题,python,Python,假设一本书的封面价格是24.95美元,但书店可以得到40%的折扣。第一份的运费为3美元,每增加一份运费为75美分。60份的总批发成本是多少 这就是我尝试过的: 价格 >>>b='折扣' >>>c='运费' >>>d='附加副本' >>>e='份数' >>>a=24.95 >>>b=0.4 >>>c=3 >>>d=0.75*59 >>>e=60 >>>打印“总成本=”,c+d 总费用=47.25 >>>f='总成本' >>>打印“总折扣=”,b*a 总折扣=9.98 >>>g='总折扣' >>>打

假设一本书的封面价格是24.95美元,但书店可以得到40%的折扣。第一份的运费为3美元,每增加一份运费为75美分。60份的总批发成本是多少

这就是我尝试过的:

价格 >>>b='折扣' >>>c='运费' >>>d='附加副本' >>>e='份数' >>>a=24.95 >>>b=0.4 >>>c=3 >>>d=0.75*59 >>>e=60 >>>打印“总成本=”,c+d 总费用=47.25 >>>f='总成本' >>>打印“总折扣=”,b*a 总折扣=9.98 >>>g='总折扣' >>>打印“折扣前总采购成本=”,a*e 折扣前总采购成本=1497.0 >>>h=“折扣前的总采购成本” >>>打印“折扣后的总采购成本=”,h-g 回溯最近一次呼叫上次: 文件,第1行,在 TypeError:-:“str”和“str”的操作数类型不受支持 >
这是一个很好的场景,python在我们的日常生活中派上了用场,了解python操作符也是一个很好的方法:

old_price = 24.95 # Set a variable for the old price
new_price = old_price * 0.6 # Set a variable for the new price
first_copy = 3 # Set a variable for the price of shipping fee for the first copy
other_copies = 0.75 * 59 # Calxulate the price of shipping fee for the following copies
whole_sales = new_price * 60 + first_copy + other_copies # Calculate the total price
print(round(whole_sales,2)) # Print the total price, rounded to the nearest cent
您得到的错误是:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'str' and 'str'
考虑到所描述的问题和采取的方法,我可能会这样做:

a = 24.95  # cover price
b = 0.4  # discount
c = 3.00  # initial shipping cost
d = 0.75  # additional items shipping cost
e = 60  # no. of copies

f = c + d * (e - 1)  # total shipping cost
print(f"total shipping cost = ${f:0,.2f}")

g = a * b  # discounted book cost
print(f"discounted book cost = ${g:0,.2f}")

h = a * e  # total purchase cost before discount (sans shipping)
print(f"total purchase cost before discount (sans shipping) = ${h:0,.2f}")

i = g * e  # total purchase cost after discount (sans shipping)
print(f"total purchase cost after discount (sans shipping) = ${i:0,.2f}")

j = h - i  # total discounted savings
print(f"total discounted savings = ${j:0,.2f}")
输出

>python3测试.py 总运费=47.25美元 贴现账面成本=9.98美元 无运费折扣前的总采购成本=$1497.00 无运费折扣后的总购买成本=598.80美元 贴现储蓄总额=898.20美元 >
你试过什么?为什么这个标签是PHP?这是学校的项目吗?
a = 24.95  # cover price
b = 0.4  # discount
c = 3.00  # initial shipping cost
d = 0.75  # additional items shipping cost
e = 60  # no. of copies

f = c + d * (e - 1)  # total shipping cost
print(f"total shipping cost = ${f:0,.2f}")

g = a * b  # discounted book cost
print(f"discounted book cost = ${g:0,.2f}")

h = a * e  # total purchase cost before discount (sans shipping)
print(f"total purchase cost before discount (sans shipping) = ${h:0,.2f}")

i = g * e  # total purchase cost after discount (sans shipping)
print(f"total purchase cost after discount (sans shipping) = ${i:0,.2f}")

j = h - i  # total discounted savings
print(f"total discounted savings = ${j:0,.2f}")