I NEED HELP WITH MY CODE IN PYTHON
PythonCoder09 opened this issue · comments
I can't find out what is wrong with this code. Can anyone help?
base_price = input("Enter cart total: ")
percent_discount = base_price - base_price * .15
fixed_discount = base_price - 12
final_price = min(fixed_discount, percent_discount)
print("Your best price is $" + final_price)
ask chat gippety
I amn't able to send file so, I am sending this comment. this is my first time to solve an issue on Github
base_price = float(input("Enter cart total: "))
percent_discount = base_price - base_price * 0.15
fixed_discount = base_price - 12.0
final_price = min(fixed_discount, percent_discount)
print("Your best price is $", final_price)
Here you go, happy Python learning (GitHub issues isn't really the place to learn Python or get help with non-relevant code, btw)
# Convert the input to an float value (will fail if user inputs non-float/int value)
base_price = float(input("Enter cart total: "))
percent_discount = base_price - (base_price * .15)
# Don't give the customer a discount if their order is below $50 (arbitrary number I set that seems fair)
if base_price >= 50: fixed_discount = base_price - 12
else: fixed_discount = base_price
final_price = min(fixed_discount, percent_discount)
print(f"Your best price is ${final_price}") # Changed to string concatenation
what are you want to do or what is your problem with this
base_price = float(input("Enter cart total: ")) # Here Converting the input to float
percent_discount = base_price - base_price * 0.15
fixed_discount = base_price - 12
final_price = min(fixed_discount, percent_discount)
print("Your best price is $" + str(final_price)) # Here, Converting final_price to string for concatenation
#Here in this code,
#The input() function returns a string, so you need to convert base_price to a numeric type (e.g., float) to perform mathematical operations.
#When using the min() function, make sure that the values being compared are of the same type. In your case, fixed_discount and percent_discount are of different types, which can lead to unexpected results.
#Now, the base_price is converted to a float, and I've added a conversion of final_price to a string before printing it. This should resolve the issues in your code.
I NEED HELP WITH MY CODE IN PYTHON #8
Convert input to float as it's received as a string
base_price = float(input("Enter cart total: "))
Calculate discounts
percent_discount = base_price * 0.15
fixed_discount = 12
Calculate final price
final_price = base_price - min(fixed_discount, percent_discount)
Format and print the result
print("Your best price is $" + format(final_price, ".2f"))
Convert the base_price to float as the input is received as a string.
Changed the calculation of percent_discount to correctly calculate 15% of the base price.
fixed_discount is set to a fixed value of 12.
Calculated final_price by subtracting the minimum of fixed_discount and percent_discount from base_price.
Formatted the final price to two decimal places for a cleaner output.
What even…
It's the Khan Academy COURSE: INTRO TO COMPUTER SCIENCE - PYTHON
UNIT 1
Lesson 4: Arithmetic expressions