Không tìm thấy nội dung mà bạn muốn tìm?
Bài đăng mới5 bình luận
-
I am having trouble with challenge: coupon codes. do you know what I am doing wrong? this is what I'm supposed to do and what I did:
-
what I'm supposed to do:
Travis can’t find the cleats at a local store, so he wants to include the shipping cost in the final price. Shipping costs can vary, so he decides to let the user enter the shipping cost themselves.
- Add a new
input()prompt that asks the user to enter a shipping cost. - Add the entered shipping cost to the final price.
You’ll need to store the result of the
input()call in a new variable. Remember that the shipping cost may include cents, like 7.99. - Add a new
-
what I did
base_price = input("Enter cart total: ")
# Available coupon codes include 15% off and $12 off.
percent_discount = float(base_price) - float(base_price) * .15
fixed_discount = float(base_price) - 12# Pick the coupon that offers the best discount.
final_price = min(fixed_discount, percent_discount)
print("Your best price is $" + str(round(final_price, 2 )) )
shipping_cost = input("Enter shipping cost: ")
final_price = shipping_cost +
print(final_price) -
please answer soon!
-
Hi,
This is the challenge you are referring to: https://www.khanacademy.org/computing/intro-to-python-fundamentals/x5279a44ae0ab15d6:computational-thinking-with-variables/x5279a44ae0ab15d6:arithmetic-expressions/pc/coupon-codes
What you did is giving this error: Traceback (most recent call last): File "main.py", line 11 final_price = shipping_cost + ^ SyntaxError: invalid syntax
I think your main problem is with input().
Maybe you can use something like this to convert shipping_cost to a float so you can add it to the final_price:
shipping_cost = input("Enter shipping cost: ")
final_price = final_price + float(shipping_cost)
print(final_price)
Vui lòng đăng nhập để lại bình luận.