• 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

    • They keep your data encrypted too. Including the calendar.
    • Microsoft makes billions redirecting people to use Bing in Microsoft Edge and selling OneDrive space. All thanks to Windows.
    • Teams is cancer, ebola and aids combined.
    • Claude on Windows is eating up massive amounts of RAM, with no way to stop it by Usama Jawad Anthropic has been in the headlines a lot lately, primarily due to its latest revenue and valuation figures, along with its release of its state-of-the-art (SOTA) Fable model. While its flagship product, Claude, may be very popular among millions of users, a lot of them are now reporting memory issues when using the tool. Over on Claude Code's GitHub repository, an issue raised in February has been gaining traction once again. Basically, Claude Desktop on Windows spins up a 1.8GB Hyper-V virtual machine if you use Claude Cowork or agent mode even once. This happens on each launch of Claude Code even if you plan to use the tool in chat mode only. Several users have upvoted this bug and stated that it's happening on their machine as well. However, it seemingly affects only Claude desktop users on Windows, not customers of the CLI or any other platform. Once the bug is triggered, it also shows a Vmmem process in Task Manager, indicating CPU usage of 0% and RAM utilization of a whopping ~1.8GB. Claude users complain that this process should only spin up when you explicitly launch agent mode or Cowork in Claude, with session files efficiently cleaned up after use. Additionally, they are calling for Claude to gracefully handle the absence of virtual machine-based infrastructure, without compromising on chat performance. It's unclear when this issue originated or what the root cause behind it is, but people are once again actively engaging in the GitHub thread as well as Hacker News. You can also find other technical details and log events over on GitHub. It's unclear if Anthropic will look into this issue, especially since it's already been reported for a few months. However, the bug is also causing major annoyance for users, with many claiming that it has led them to uninstall Claude Code on desktop, as a concrete workaround is not yet known.
    • "The US innovates, China replicates, Europe regulates" -- let's see who makes the cut
  • Recent Achievements

    • One Month Later
      Sopa flores earned a badge
      One Month Later
    • First Post
      StaticMatrix earned a badge
      First Post
    • Week One Done
      StaticMatrix earned a badge
      Week One Done
    • Rookie
      lamborghiniv10 went up a rank
      Rookie
    • One Month Later
      pinnclepd earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      534
    2. 2
      PsYcHoKiLLa
      209
    3. 3
      +Edouard
      154
    4. 4
      Steven P.
      100
    5. 5
      ATLien_0
      84
  • Tell a friend

    Love Neowin? Tell a friend!