• 0

What is wrong with this code?!? 0_o


Question

So I'm taking a Python class right now at my college and part of tonight's lab was creating this code using our knowledge thus far

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:

  1. 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

Joe also performs other routine services and charges for parts and labor ($20.00 per hour).

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()
[/CODE]

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

Link to comment
https://www.neowin.net/forum/topic/1072715-what-is-wrong-with-this-code-0_o/
Share on other sites

2 answers to this question

Recommended Posts

  • 0

lol wow, I feel derp now :p

both me and my teacher kept looking over that for like 15 minutes, I can't believe we overlooked that lol :D

thanks for the help jkenn99, I guess it's just been a long day

This topic is now closed to further replies.
  • Posts

    • I don't get this David. Can you explain it please.  
    • Microsoft is busy. Lots of changes to be released imminently for Windows server or soon. Also, lots happening for next version as well. Third party virus scanning software is being moved out of Kernel mode to avoid repeat of Crowdstrike incident. Windows Protected Mode and Windows Ready Print no longer require third party print drivers to be installed. New storage stack being developed. New NVME drivers now available for Windows Server 2025 to improve local NVME drive performance by 60+ percent. NVME-Of of fabric being worked on for next release to improve network access to NVME drives. ReFs (next file system) now has ability to boot and will become default file system in next release of Windows Server. ReFs improves on NTFS in several areas including resiliency and reliability and scalability. New update stack is being worked on to unify Windows updates, and updates for drivers and first party/3rd party application software. A stricter and more robust third-party driver certification program (ODI) is being worked on to improve performance, thermals, battery life, and reliability on modern Windows hardware by tightening how OEMs and IHVs (Intel, AMD, Qualcomm, NVIDIA, etc.) build and ship drivers. There is a tone more but too numerous to mention.
    • Now disable that stupid OneDrive backup request when Windows starts please. So unbelievably frustrating to only have “remind me later” instead of “no and never ask me again”
    • Hello, The Media Creation Tool is still at v10.0.26100.7019 from October 2025. Just looks like the backend has been updated. Regards, Aryeh Goretsky
    • Since they open sourced the calculator in Win 10/11 it is much better and can do a lot, I love it.
  • Recent Achievements

    • One Month Later
      Markus94287 earned a badge
      One Month Later
    • Week One Done
      Markus94287 earned a badge
      Week One Done
    • One Year In
      Markus94287 earned a badge
      One Year In
    • Dedicated
      truespursfan earned a badge
      Dedicated
    • Rookie
      restore went up a rank
      Rookie
  • Popular Contributors

    1. 1
      +primortal
      508
    2. 2
      +Edouard
      169
    3. 3
      PsYcHoKiLLa
      154
    4. 4
      ATLien_0
      90
    5. 5
      Steven P.
      79
  • Tell a friend

    Love Neowin? Tell a friend!