输入和浮动字符串错误

Input and Floating Strings errors

我正在尝试在 Python 上构建价格计算器,但收到以下错误: TypeError: 'str' object is not callable 在我的代码的这一行:

tax_rate = float(input("What is the sales tax rate? "))

完整代码是这个:

print("Please enter the following information:")
print()
child_meal = float(input("What is the price of a child's meal? "))
adult_meal = float(input("What is the price of an adult's meal? "))
child_number = input=("What is the number of childrens? ")
adult_number = input=("What is the number of adults? ")
tax_rate = float(input("What is the sales tax rate? "))

total_child_meal = int(child_meal) * int(child_number)
total_adult_meal = int(adult_meal) * int(adult_number)
sub_total = int(total_child_meal) + int(total_adult_meal)
sales_tax = float(sub_total) * float(tax_rate) / 100
total_amount = float(sub_total) + float(sales_tax)
print()
print(f"What's the price of a child's meal? {child_meal}")
print(f"What's the price of an adult's meal? {adult_meal}")
print(f"How many children are there? {child_number}")
print(f"How many adults are there? {adult_number}")
print(f"What is the sales tax rate? {tax_rate}")
print()
print(f"Subtotal: {sub_total}")
print(f"Sales Tax: {sales_tax}")
print(f"Total: {total_amount}")
print()
payment_amount = float(input("What is the payment amount? "))
change = float(payment_amount) - float(total_amount)
print(f"Change: {change}")

我不确定为什么 tax_rate 字符串行失败,因为我在 child_meal 字符串中使用的浮点字符串示例相同。

你能帮我找出这里的错误吗?非常感谢!

在代码的第 5ht 行和第 6 行,你这里有点乱。哪个好!

你有什么

child_number = input=("What is the number of childrens? ")
adult_number = input=("What is the number of adults? ")

随心所欲

你想要的是去掉输入和参数之间的“=”。

child_number = input("What is the number of childrens? ")
adult_number = input("What is the number of adults? ")

之后,代码运行良好!干得漂亮。

如果你想获得用户的输入:

child_number = input("What is the number of childrens? ")
adult_number = input("What is the number of adults? ")