我不熟悉编码/python,因此非常感谢您的帮助。我正试图找出如何将userQuantityPurchased和userPrice添加在一起,但我不知道该怎么做。这是Python btw,因此提前感谢您
#Write a program that will ask the User to enter the Customer Name, Quantity purchased, and the Price per unit. The program should compute the Sales Amount, State and County
#sales taxes. The program should also computer the net sales and discount givenn tot he customer after deduction of the sales taxes from the gross sales. Assume the state sales tax is 9 percent, County sales tax is 5 percent, and discount is %10. A lop should prompt the user to enter yes(y) to process another record or not.sum
import math
userName = input("Enter Customer Name: ")
userQuantityPurchased = int(input("Enter Quantity Purchased: "))
userPrice = int(input("Enter Price per Unit: "))
print("------------------------------")
print("Here is your Net Sale!")
print("------------------------------")
print("Customer Name: " + userName)
print("Sales Amount: " + userQuantityPurchased + userPrice)
我建议根据PEP8中设置的约定使用f字符串和名称变量
所以代码可以是这样的:
使用此选项连接值:
或:
连接总和
问题是:
您有一个字符串,您正试图向其中添加一个数字。
+
运算符可以将字符串连接在一起,但不会自动将数字连接到字符串。您必须将数字量转换为字符串才能将其串联:虽然基于变量名,但您似乎希望实际将乘以
userPrice
乘以userQuantityPurchased
,这样总金额将等于所有购买物品的总成本:相关问题 更多 >
编程相关推荐