excelCPU icon indicating copy to clipboard operation
excelCPU copied to clipboard

I NEED HELP WITH MY CODE IN PYTHON

Open PythonCoder09 opened this issue 1 year ago • 8 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)

PythonCoder09 avatar Feb 01 '24 23:02 PythonCoder09

ask chat gippety

br3nr avatar Feb 02 '24 02:02 br3nr

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)

ghost avatar Feb 02 '24 02:02 ghost

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

aut-mn avatar Feb 02 '24 02:02 aut-mn

what are you want to do or what is your problem with this

Ndjieudja avatar Feb 02 '24 11:02 Ndjieudja

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.

APrakashzb07 avatar Feb 02 '24 18:02 APrakashzb07

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.

himanshuCoder2 avatar Feb 03 '24 09:02 himanshuCoder2

What even…

elsandosgrande avatar Feb 05 '24 20:02 elsandosgrande

It's the Khan Academy COURSE: INTRO TO COMPUTER SCIENCE - PYTHON

UNIT 1 Lesson 4: Arithmetic expressions

proce55or avatar Mar 23 '24 20:03 proce55or