小编Joh*_*DOe的帖子

Python 中的字符串格式美元符号

所以我试图让美元符号直接出现在“成本”列下数字的左侧。我无法解决这个问题,任何帮助表示赞赏。

# Question 5

print("\nQuestion 5.")

# Get amount of each type of ticket to be purchased

adultTickets = input("\nHow many adult tickets you want to order: ")

adultCost = int(adultTickets) * 50.5

childTickets = input("How many children (>=10 years old) tickets: ")

childCost = int(childTickets) * 10.5

youngChildTickets = input("How many children (<10 years old) tickets: ")

# Display ticket info

print ("\n{0:<17} {1:>17} {2:>12}".format("Type", "Number of tickets", 
"Cost"))

print ("{0:<17} {1:>17}${2:>12.2f}".format("Adult", adultTickets, adultCost))

print ("{0:<17} {1:>17}${2:>12.2f}".format("Children (>=10)", childTickets, …
Run Code Online (Sandbox Code Playgroud)

python string-formatting

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

python ×1

string-formatting ×1