#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    1
    Rep Power
    0

    Need help with car salesman program.


    base = int(input("What was the base price of the car? "))
    tax = base * .06
    license = base * .02
    print("tax: $",tax)
    print("license: $",license)
    dp = print("dealer prep: $200")
    delivery = print("delivery: $500")
    total = base + tax + license + dp + delivery
    print("The total price of your car is:", total)

    I get the error message Traceback (most recent call last):
    File "/Users/brianking/Documents/Dealer", line 8, in <module>
    total = base + tax + license + dp + delivery
    TypeError: unsupported operand type(s) for +: 'float' and 'NoneType'

    Anybody know what is going on, also is this the easiest way to code this program or can I somehow print the license at tax without starting a new line. Thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    83
    Rep Power
    39
    The reason that your code doesn't work is that dp and delivery are None and you can't do arithmetic with None as the error message tells you.

    Why are they None? Because print returns None.

    Code:
    dp = print("dealer prep: $200")
    delivery = print("delivery: $500")
    What do you expect the values of dp and delivery to be after those two lines if not None?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    39
    Rep Power
    3
    sepp2k1 has correctly identified the problem. I assume you meant for dp to be 200 and delivery to be 500 so either of the following would work

    Code:
    # ignore dp and delivery as they are constant
    print("dealer prep: $200")
    print("delivery: $500")
    total = base + tax + license + 200 + 500
    
    # set dp and delivery seperately to the print statement
    dp = 200
    print("dealer prep: $",dp)
    delivery = 500
    print("delivery: $",delivery)
    total = base + tax + license + dp + delivery
    The second method has the slight advantage in making it clear where to change the dp and delivery values in future.
    Last edited by Quackajack; July 26th, 2012 at 04:41 AM. Reason: Added clarification

IMN logo majestic logo threadwatch logo seochat tools logo