2

I am trying to create a cash register program. My objective is for all the products be added and the final price be found. How can I reach this goal without knowing the values previously? Below is my code. Thanks in advance for any help it is greatly appreciated

responses = {}

polling_active = True

print("Welcome to the cash register. Insert your product name and price to be able to calculate your final total")


total = 0

while polling_active:
    product = input("\nProduct Name: ")
    total += float(input("Price: "))

    responses[product] = total

    repeat = input("Is this your final checkout? (Yes/No)")
    if repeat == 'no':
        polling_active = True
    elif repeat == 'No':
        polling_active = True
    elif repeat == 'Yes':
        polling_active = False
    elif repeat == 'yes':
        polling_active = False
    else:
        print("That operation is invalid")

print("\n---Final Checkout---")
for product, price in responses.items():
    print(product + " is $" + str(total))

print("\n---Total Price---")
print("Store Price is: ")
print("$" + str(total))

print("\n---Tax Price---")
print("Your price with tax is: ")

total = total * 1.13

print("$" + "{0:.2f}".format(float(total)))

print("\nThank you for shopping with us! Have a great day!")

I understand the with my current code, total will not allow me to add any products but that is just currently a place holder

6
  • So, you want to calculate the total without actually knowing the items prices? Commented May 2, 2017 at 1:46
  • Yes, Exactly. For example you could input 10 items or 5 Commented May 2, 2017 at 1:48
  • It just needs to find the total cost of any amount Commented May 2, 2017 at 1:48
  • you may use sum(responses.values()) Commented May 2, 2017 at 1:48
  • Where would I input that into the code Commented May 2, 2017 at 1:50

1 Answer 1

2

Here is the code that you need:

responses = {}

polling_active = True

print("Welcome to the cash register. Insert your product name and price to be able to calculate your final total")

while polling_active:
    product = input("\nProduct Name: ")
    price = float(input("Price: "))

    responses[str(product)] = price

    repeat = raw_input("Is this your final checkout? (Yes/No)")
    if repeat.lower() == 'no':
        polling_active = True
    elif repeat.lower() == 'yes':
        polling_active = False
    else:
        print("That operation is invalid")

print("\n---Final Checkout---")
for product, price in responses.items():
    print(product + " is $" + str(price))

print("\n---Total Price---")
print("Store Price is: ")
total= sum(responses.values())
print("$" + str(total))

print("\n---Tax Price---")
print("Your price with tax is: ")

total = total * 1.13

print("$" + "{0:.2f}".format(float(total)))

print("\nThank you for shopping with us! Have a great day!")

Output:

integer: enter image description here

float: enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

How could I fix this? Otherwise it fixes the rest of the problem
Never mind I solved it. The error was when using floats (like 2.23 or 3.99) it didn't add them
alright, although i have made small changes in program like using .lower() and added float screenshot as well. Please upvote if i did what you wanted.
Thanks a lot for the help. I have uprooted it and marked it as the answer. Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.