我正在为自己的班级使用python做一个简单的程序,除了没有弄清楚如何使美元符号显示在总和旁边之外,我基本上将其记下了。这是我的代码:
item1 = input("Enter price of first item: $");
item2 = input("Enter price of second item:$");
item3 = input("Enter price of third item: $");
total = (item1 + item2 + item3);
print("The total of the three items is:$", total);
答案 0 :(得分:0)
尝试
print("The total of the three items is:${}".format(total))
如果在python 3.6或更高版本中,您还可以使用f-Strings
:
print(f"The total of the three items is:${total}")
“老式方式”是使用%s
格式化程序:
print("To total of the three items is:$%s" % total)