Sales Tax using functions


#1

Need help writing a code for the following sales tax calculator:

Console Output:

Sales Tax Calculator

Enter the cost of each item (ENTER 0 TO END)
Cost of item: 35.99
Cost of item: 27.50
Cost of item: 19.59
Cost of item: 0
Total: 83.08
Sales tax: 4.98
Total after tax: 88.06

Again? (y/n): y

Enter the cost of each item (ENTER 0 TO END)
Cost of item: 152.50
Cost of item: 59.80
Cost of item: 0
Total: 212.3
Sales tax: 12.74
Total after tax: 225.04

Again? (y/n): n

Thanks, bye!

Specifications
The sales tax rate should be 6% of the total.
Your program should also contain functions that:
calculate the sales tax
calculate the total after tax
asks the user to enter a number repeatedly until they are done, adds each number to a total variable and uses a counter to determine how many numbers were entered.
outputs the total before tax, the tax and the total including tax.
These functions should round the results to a maximum of two decimal places.
Assume the user will enter valid data.

THIS IS WHAT I HAVE SO FAR

#ask price of each item

item1 = float(input(“Enter the price of item1”))

item2 = float(input(“Enter the price of item2”))

item3 = float(input(“Enter the price of item3”))

#calculate the subtotal of items

sub_total = (item1 + item2 +item3)

#calculate the tax

sales_tax = sub_total * 0.06

#calculate total

total = sub_total + sales_tax

#display subtotal, sales tax, and total

print(“sub total:”)

print(“sales total:”)


#2

We can help you, but you have to write the code. What do you have so far? Ask specific questions you need help with, don’t expect us to write the program for you, that is not how assignments are done


#3
#ask price of each item

item1 = float(input("Enter the price of item1"))

item2 = float(input("Enter the price of item2"))

item3 = float(input("Enter the price of item3"))

#calculate the subtotal of items

sub_total = (item1 + item2 +item3)

#calculate the tax

sales_tax = sub_total * 0.06

#calculate total

total = sub_total + sales_tax

#display subtotal, sales tax, and total

print("sub total:")

print("sales total:")

#4

what is it you do not understand and would like help with?


#5

How do I integrate functions into my code? I’ve read my chapter about how functions work and how they are used to “call” them but I am struggling integrating them into my calculator.


#6

Reading about a concept isn’t enough, you have to implement it. start by building the simplest function you can think of:

# declaring function
def example():
   print "hello world"

# calling function
example()

then expand the function, add a parameter, see what that does, and so on. Designing function requires practice.

learn about return, which is really useful


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.