我该怎么加2.50元的费用?你知道吗
现在它只是把它打印成2。你知道吗
cost = 0.00
r = open("toppings.txt")
bases = ["small","medium","large"]
toppings = ["Pepperoni","Chicken","Cajun Chicken","Mushrooms",
"Red Onions","Sweetcorn","Ham","Cheese","Spicy Minced Beef",
"Anchovies","Tuna","Peppers","Jalapenos","Green Chillies"] #0-13
def small():
current = cost + 2.50
print("Your current total cost is " + "£" + str(int(current)))
int
把一个数变成一个整数。例如,int(2.1) = 2
最后一行应该只有
str(current)
。你知道吗有两个问题:
int(current)
中的^{我建议只使用带“2”小数位的^{} (这里由
.2f
强制执行):如果您使用的是类似于“money”的变量,那么应该使用^{} 而不是float,这样您就不需要考虑浮点数的“不精确性”。你知道吗
您正在将此行中的浮动当前账单金额转换为int
而是使用此命令打印当前账单金额。你知道吗
输出
相关问题 更多 >
编程相关推荐