179k views
3 votes
Read the following code used to calculate the total cost of an item with tax: price = input("What is the item price? ") tax = price * 0.065 totalPrice = price + tax There is an error in the code. What type of function needs to be used? (5 points) float() int() print() str()

User Jrbj
by
4.0k points

1 Answer

6 votes

Answer: float()

Explanation: The code used to calculate total price = tax + price.

price = input("What is the item price? ")

tax = price * 0.065

totalPrice = price + tax

Since the input required from the user will be numerical, that is the price of an item, then it has to be stated explicitly, instead the code throws an error as it will read in a string if not stated explicitly.

Also, Given that the total price calculation will require decimal or fractional calculations, using the float() function will allow the program to read in the user input as a numerical value which can be used in further calculation as the float () function provides flexibity when working with fractional values.

User GraveyardQueen
by
4.1k points