0

Why does this not work? (Python)

#Gets price price = input() tax_rate = 6 #Caculates tax and prints total = ((price / tax_rate) + price) print(total)

11th Oct 2024, 10:11 PM
SwiftSand
SwiftSand - avatar
3 Réponses
+ 2
input() always returns a string
11th Oct 2024, 10:54 PM
Lisa
Lisa - avatar
+ 1
# The int() function converts a number or a string to its equivalent integer price = int(input())
11th Oct 2024, 10:53 PM
SoloProg
SoloProg - avatar
+ 1
SwiftSand as others mentioned, price has to get converted from string to a number by using float() (or maybe int(), depending on task requirements). I would add that the code uses tax_rate as a fraction. Is it correct? In my experience tax rate is usually a percentage.
12th Oct 2024, 1:31 PM
Brian
Brian - avatar