• 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 have a problem with adverts, I not fond of the tracking. My main problem is when you have to keep clicking close to remove them before you can see anything On the site. The ones that keep updating and moving stuff around as they are different sizes are as bad. Neowin is not too bad with Adverts, but ones that keeps updating or have animation can be distracting when reading something, like the one showing now, about how much should I walk to lose weight. I realise sites need adverts to survive, but stop changing them every few seconds.
    • SQL Server Management Studio 22.7 brings "What's New" page, T-SQL formatting, and lots more by Usama Jawad SQL Server Management Studio (SSMS) is the tool of choice for most developers working with SQL infrastructure and data. Microsoft recently released SSMS version 22, and in the past few months, it has been steadily releasing point upgrades to refine the integrated development environment (IDE). Now, it has released SSMS version 22.7.0 with a bunch of new features and interfaces. For starters, SSMS 22.7 has netted a native "What's New" page, which highlights the top features and bug fixes present in the latest release. However, Microsoft says that this page won't annoy you much as it will only show up each time you update SSMS, and once you dismiss it, it won't be shown again to you until the next release. Secondly, Microsoft has finally introduced T-SQL formatting inside SSMS. The good thing about this is that it does not require installing any additional components, as it is built into the native experience. All you have to do is right-click the query editor window and select Format SQL from the context menu. Additionally, you also have several customization options at your disposal, such as the ability to automatically place semicolons at the end of a statement, split clauses across multiple lines, and more. However, this capability is only in preview for now. Additionally, Microsoft has introduced a preview of Agent Mode, which allows the AI model to automatically perform complex workflows on your behalf. Furthermore, Agent Mode will operate in read-only mode by default, so that you don't have to worry about the AI model accidentally deleting your data. On a related note, Microsoft is finally allowing users to configure the execution context of GitHub Copilot. This can be controlled per database using the CONSTITUTION.md file, where you specify the user details for the agentic executor. You can find details about this and additional bugfixes in Microsoft's blog post here.
    • I only use 3 extensions in Zen. I don't need or want a ton of stuff in my browser i don't use.
    • I prefer to choose my own ad bockers, not what the browser seems to think I need. i remember the days when a browser was just that, now they try and be everything and add stuff in that not all of us want. I bet Brave is full of AI rubbish? I will stick with Zen, not perfect, but better than others.
  • Recent Achievements

    • One Month Later
      johnjacobb40 earned a badge
      One Month Later
    • One Year In
      Primer1st earned a badge
      One Year In
    • Experienced
      JayZJay went up a rank
      Experienced
    • Reacting Well
      Sir_Timbit earned a badge
      Reacting Well
    • Week One Done
      rubentuben8 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      516
    2. 2
      PsYcHoKiLLa
      231
    3. 3
      +Edouard
      144
    4. 4
      ATLien_0
      86
    5. 5
      Steven P.
      82
  • Tell a friend

    Love Neowin? Tell a friend!