Home > Enterprise >  Input and Floating Strings errors
Input and Floating Strings errors

Time:05-08

I'm trying to construct a Price calculator on Python and I'm receiving the following error: TypeError: 'str' object is not callable On this line of my code:

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

The complete code is this one:

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}")

I'm not sure why the line for tax_rate string is failing since is the same example for float string I used in child_meal string.

Can you help me to identify the error here? I truly appreciate!

CodePudding user response:

On the 5ht and 6th lines of your code, you have a bit of a mess up here. Which is fine!

What You Have

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

What You Want

What you want is to get rid of the "=" between the input and the parameters.

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

After that, the code works great! Nice work.

CodePudding user response:

if you want to get input from user:

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