-1

the reason i have signed up here today is to ask for a hint to where i'm going wrong in this argument. i am very new to coding and was hoping i might be able to get some help. i feel i'm slightly cheating myself by asking for help so early, so if someone can explain where I've made mistakes i would like to try and figure out how to correct them, clues and hints would be appreciated but i would really like to understand where the errors are what to do to correct them and why, so please don't just paste the answer. thanks

ok here is my attempt at Writing a Car salesman program where the user enters the base price of a car. The program should add a bunch of extra fees such as tax, license, dealer prep, and destination charge. Make tax and license a percent of the base price. The other fees should be set values. Display the actual price of the car once all the extras are applied.

    base_price = float(input("please enter base price of car",))

    taxes *=0.06
    float(input(taxes))
    licence *= 0.01
    float(input(licence))

    premium_pack += 1250
    print("premium pack + 1250")

    total_price = base_price + premium_pack + taxes + licence

    print("\n\total price:", total_price))

    input("\n\npress enter key to exit")

the last time i ran the program i had a name error

    taxes *= 0.06
    NamError: name 'taxes' is not defined

o.k. i hope this information helps and thank you for your time in advance

alex

5 Answers5

4

taxes*=0.06 is shorthand for taxes = taxes * 0.06. Which you have not yet defined. I think what you actually meant to write was

taxes = base_price * 0.06

You'll still have other issues with this program, though.

Wayne Werner
  • 49,299
  • 29
  • 200
  • 290
1

You seem to be unclear on what the *= and += operators do. What you want is to assign taxes (and the other variables) some values equal to base_price * 0.06 and so on. Use the = operator to assign values to a variable (like you did in the first line), and the * operator to multiply two values together (e.g. base_price * 0.06).

You've got this problem in several places, as well as an issue where I think you don't know what the input function does: if you just want to display a value, you should use the print function.

I highly recommend going through the tutorials. They do a good job covering this sort of stuff.

Henry Keiter
  • 16,863
  • 7
  • 51
  • 80
1

taxes *= 0.06 is shorthand for taxes = taxes * 0.06, , i.e., the new value of taxes is 0.06 times the old value of taxes. Thus the interpreter is complaining that you haven't defined taxes before using it on the right hand side.

Presumably what you want is:

taxes = 0.06 * base

or

taxes = 0.06 * float(raw_input('Enter amount to be taxed'))
forefinger
  • 3,767
  • 1
  • 22
  • 18
0
  1. You are incorrectly using the *= and += statements.
  2. You can't use the taxes *=0.06 statement unless you have defined taxes previously. Same is the case with licence and premium_pack.
  3. Also, the statement float(input(taxes)) is wrong, you need to pass a string as an argument to it. (http://docs.python.org/3/library/functions.html#input)
  4. Next, if you are using python 2.7, the usage of the input statement is incorrect - you should use raw_input instead. (https://stackoverflow.com/a/3800862/1860929)
  5. There is an extra closing bracket in print("\n\total price:", total_price)) statement
  6. You are using an extra \ after \n due to which, the t of total will get escaped.
  7. Finally, you need to check the logic itself. As @Wayne has pointed in his answer, you probably want to do taxes = base_price * 0.06 and not taxes = taxes * 0.06

Check the following code, I think you are looking for something similar

base_price = float(raw_input("Please enter base price of car",))

taxes = 0.06 * base_price
print("Taxes: %s" %taxes)

licence = 0.01 * base_price
print("Licence: %s" %licence)

premium_pack = 1250
print("premium pack: 1250")

total_price = base_price + premium_pack + taxes + licence

print("\ntotal price: %s" %total_price)

raw_input("\n\npress enter key to exit")
Community
  • 1
  • 1
Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
0

The line taxes *= 0.06 means, taxes = taxes * 0.06. Python is telling you that it doesn't know what the value of taxes is (because you haven't assigned it a value).

licence and premium_pack have the same issue.

ForeverWintr
  • 5,492
  • 2
  • 36
  • 65
  • thank you for your responses guys, yes i'm using 2.7 and im reading from the 'python programming 3rd edition for the absolute beginner. i understand more clearly now what i have to do and appreciate the feedback, when i have completed the task i'll rate the best answer if that is o.k. but thanks to all – user2879924 Oct 14 '13 at 21:41