输入
流程
输出
#Input (Receive info)
charge_for_toy = float(input('\nEnter charge for toy: $'))
#Process (Calculate info)
SALES_TAX = .07
sales_tax = (charge_for_toy + SALES_TAX)
grand_total = charge_for_toy + sales_tax
#Output (display info)
print('\nCharge for toy = $', format(charge_for_toy, ',.2f'), sep='')
print('Sales tax = $', format(sales_tax, ',.2f'), sep='')
print('Grand total = $', format(grand_total, ',.2f'), sep='', end='\n\n')`
我尝试在“获取玩具名称和订购数量”中输入与我相同的行
charge_for_toy = float(inpuit('\nEnter charge for toy: $'))
我被告知绳子不能漂浮。我有点不知道如何继续。
我尝试在“获取玩具名称和订购数量”中输入与我相同的行
因此,如果您想要名称中包含字母,则不能使用“同一行”。
input
默认为字符串,因此您需要的是:
#Input (Receive info)
name_for_toy = input('Enter toy name: ')
charge_for_toy = float(input('Enter charge for toy: $'))
toy_quantity = int(input('Enter toy quantity: ')) # int because can't have fraction of toy
#Process (Calculate info)
SALES_TAX = 0.07
subtotal = charge_for_toy * toy_quantity
sales_tax = subtotal * SALES_TAX # corrected, "+ SALES_TAX" incorrect here
grand_total = subtotal + sales_tax
#Output (display info)
print('Toy name =', name_for_toy)
print('Charge for toy = $', format(charge_for_toy, ',.2f'))
print('Sales tax = $', format(sales_tax, ',.2f'))
print('Grand total = $', format(grand_total, ',.2f'), end='\n\n')