even my teacher was stumped at what is wrong with the code
for some reason a couple of my variables are switching with each other in my output (parts price and tax) and I have no idea what is causing it
I already turned in the lab as my teacher said he wouldn't dock me points for it, I'm just curious as to what the problem is.
here is the lab question:
- Joe’s Automotive
Create an application that displays the total bill for a customer’s visit to Joe’s. Your program must make use of functions. You determine what functions are needed. My Joe’s Automotive program used 12 functions, including the main (hint). My program also used 1 global variable to store the charge for parts. Your solution should use only 1 global variable or… the program can be written without using any global variables. Remember to add comments to your program.
Joe’s Automotive performs the following routine maintenance services:
- Oil change - $26.00
- Lube job - $18.00
- Radiator flush - $30.00
- Transmission flush - $80.00
- Inspection - $15.00
- Muffler replacement - $100.00
- Tire rotation - $20.00
You will need to determine what services the customer had completed. In addition, you will need to determine if any other routine services were performed other than those listed – basically ask if other services were performed – if yes, ask for the charge for parts and ask how many hours were expended doing those other routine services.
Your output should show the following where 999 are the dollar amounts and allow for a 2 decimal place precision.
Services and Labor Charge: 999.99
Parts Charge: 999.99
Tax on Parts (6%): 999.99
Total Charges: $9999.99
and here is the code I came up with:
#Joe's Automotive bill program #Brandon Hash charge = 0.0 def main(): serviceCheck() cparts = parts() ctax = tax(cparts) total(ctax, cparts) def serviceCheck(): global charge service = raw_input ("Enter the service performed") if service == "oil": charge = 26.00 elif service == "lube": charge = 18.00 elif service == "rad": charge = 30.00 elif service == "tran": charge = 80.00 elif service == "ins": charge = 15.00 elif service == "muf": charge = 100.00 elif service == "tire": charge = 20.00 check() def check(): more = raw_input("Where there any more routine services performed?") if more == "yes": serviceCheck2() else: labor() def serviceCheck2(): global charge service = raw_input ("Enter the service performed") if service == "oil": charge = (charge + 26.00) elif service == "lube": charge = (charge + 18.00) elif service == "rad": charge = (charge + 30.00) elif service == "tran": charge = (charge + 80.00) elif service == "ins": charge = (charge + 15.00) elif service == "muf": charge = (charge + 100.00) elif service == "tir": charge = (charge + 20.00) check() def labor(): global charge tlabor = input ("How many hours of were put into the car?") charge = charge + (tlabor * 20.00) def parts(): yparts = raw_input("Were any parts needed?") if yparts == "yes": cparts = input("Enter the ammount for those parts.") else: cparts = 0.0 return cparts def tax(cparts): global charge ctax = ((charge + cparts) * .06) return ctax def total(cparts, ctax): global charge print "Receipt:" print print "Services and Labor: $ %.2f"% charge print "Parts Charge: \t \t $ %.2f"% cparts print "Tax: \t \t \t \t $ %.2f"% ctax print "Total: \t \t \t \t $ %.2f"% (charge + cparts + ctax) main()
if you need any more info let me know, I'm completely stumped at what the problem is
here's the python file as well
Lab 6 Joes Automotive.zip 767bytes 11 downloads