[noob] Error!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • administrata

    #1

    [noob] Error!

    I'm programming Car Salesman Program.
    It's been "3 days" learning python...
    But, i got problem


    Write a Car Salesman program where the user enters the base price of a
    car. The program should add on 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.

    print "CAR SALESMAN PROGRAM"
    print "\nEnter data."
    base_price = int(raw_input(" Base Price: "))

    tax = int(raw_input("/nTax: "))
    license1 = int(raw_input(" License: "))
    dealer = 30
    charge = 5
    print "Dealer Prep: ", dealer
    print "Destinatio n Charge: ", charge

    actual_price = (((base_price * tax / 100) + license1 / 100) + dealer +
    change
    print "\n\nActual price: ", actual_price

    raw_input("")

    error occurs, i think the problem is in actual_price. but,
    I don't know how to comebine percentage and raw_input.
    help me...

    thx 4 reading... :)
  • Jeff Shannon

    #2
    Re: [noob] Error!

    administrata wrote:
    [color=blue]
    > Write a Car Salesman program [...][/color]

    This sounds like homework, and we generally try to avoid solving
    peoples' homework problems for them, but I can offer a suggestion.
    [color=blue]
    > error occurs, i think the problem is in actual_price. but,
    > I don't know how to comebine percentage and raw_input.
    > help me...[/color]

    It's hard to be sure since you don't say what the error is, nor
    anything about what you expect to see and what you actually see.

    However, if you're pretty sure that the problem is the line where you
    calculate actual_price, then fire up an interactive interpreter and
    try fiddling with things. You've got a lot of subexpressions there;
    pick some values and try each subexpression, one at a time, and take a
    look at what you get.

    I bet that it won't take you long to figure out why you're not getting
    the result you expect.

    Jeff Shannon
    Technician/Programmer
    Credit International

    Comment

    • Brian van den Broek

      #3
      Re: [noob] Error!

      administrata said unto the world upon 2005-02-04 17:59:[color=blue]
      > I'm programming Car Salesman Program.
      > It's been "3 days" learning python...
      > But, i got problem
      >
      >
      > Write a Car Salesman program where the user enters the base price of a
      > car. The program should add on 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.
      >
      > print "CAR SALESMAN PROGRAM"
      > print "\nEnter data."
      > base_price = int(raw_input(" Base Price: "))
      >
      > tax = int(raw_input("/nTax: "))
      > license1 = int(raw_input(" License: "))
      > dealer = 30
      > charge = 5
      > print "Dealer Prep: ", dealer
      > print "Destinatio n Charge: ", charge
      >
      > actual_price = (((base_price * tax / 100) + license1 / 100) + dealer +
      > change
      > print "\n\nActual price: ", actual_price
      >
      > raw_input("")
      >
      > error occurs, i think the problem is in actual_price. but,
      > I don't know how to comebine percentage and raw_input.
      > help me...
      >
      > thx 4 reading... :)[/color]

      Hi,

      a couple of general tips for seeking help:

      1) "error occurs" isn't helpful. What's the error? How do you know? Is
      it that you don't get the expected output? Then show what you get and
      say what you expected. Is it that you get a traceback giving detailed
      and helpful information to track down the error? Then include those
      details in your post. (They might not make sense to you, but they will
      help helpers help you.)

      2) This smells like a homework problem. If it is, say so. That way, no
      one will think you are trying to get someone to do your homework for
      you, and will be much more receptive to request for a push in the
      right direction.

      Looking at the line:

      actual_price = (((base_price * tax / 100) + license1 / 100) + dealer +
      change

      I see you've 3 '('s, but only 2 ')'s.

      Also, because of point (1), I cannot know if this is relevant to your
      sense that there is an error, but in:

      (base_price * tax / 100)

      you might try changing 100 to 100.0. Run these through the interpreter:
      1 / 10
      1 / 10.0
      and consult the FAQ on www.python.org for an explanation of the
      difference.

      Best,

      Brian vdB

      Comment

      • John Machin

        #4
        Re: Error!


        administrata wrote:[color=blue]
        > I'm programming Car Salesman Program.
        > It's been "3 days" learning python...[/color]
        [color=blue]
        >From whom or what book or what tutorial?[/color]
        [color=blue]
        > But, i got problem[/color]

        You got problemS. What Jeff & Brian wrote, plus:

        You have "change" instead of "charge".

        You forgot to add in the base price -- "actual price" according to you
        comprises only the taxes and fees. Where is your car yard? We'd each
        like to order a nice shiny red Ferrari :-)

        Cheers,
        John

        Comment

        • administrata

          #5
          Re: Error!

          "John Machin" <sjmachin@lexic on.net> wrote in message news:<110756307 0.861085.180680 @g14g2000cwa.go oglegroups.com> ...[color=blue]
          > administrata wrote:[color=green]
          > > I'm programming Car Salesman Program.
          > > It's been "3 days" learning python...[/color]
          >[color=green]
          > >From whom or what book or what tutorial?[/color]
          >[color=green]
          > > But, i got problem[/color]
          >
          > You got problemS. What Jeff & Brian wrote, plus:
          >
          > You have "change" instead of "charge".
          >
          > You forgot to add in the base price -- "actual price" according to you
          > comprises only the taxes and fees. Where is your car yard? We'd each
          > like to order a nice shiny red Ferrari :-)
          >
          > Cheers,
          > John[/color]

          erm... sry i don't get it :\

          can you modify actual_price?

          actual_price = (((base_price * tax / 100) + license1 / 100) + dealer +
          charge

          Comment

          • Steve Holden

            #6
            Re: Error!

            administrata wrote:
            [color=blue]
            > "John Machin" <sjmachin@lexic on.net> wrote in message news:<110756307 0.861085.180680 @g14g2000cwa.go oglegroups.com> ...
            >[color=green]
            >>administrat a wrote:
            >>[color=darkred]
            >>>I'm programming Car Salesman Program.
            >>>It's been "3 days" learning python...[/color]
            >>[color=darkred]
            >>>From whom or what book or what tutorial?[/color]
            >>
            >>[color=darkred]
            >>>But, i got problem[/color]
            >>
            >>You got problemS. What Jeff & Brian wrote, plus:
            >>
            >>You have "change" instead of "charge".
            >>
            >>You forgot to add in the base price -- "actual price" according to you
            >>comprises only the taxes and fees. Where is your car yard? We'd each
            >>like to order a nice shiny red Ferrari :-)
            >>
            >>Cheers,
            >>John[/color]
            >
            >
            > erm... sry i don't get it :\
            >[/color]
            He's referring to the fact that your calculations, probably through
            inexperience with programming, don't appear to add tax to the base price
            but rather simply compute tax from it.

            Don't worry, it wasn't *that* funny :-)
            [color=blue]
            > can you modify actual_price?
            >
            > actual_price = (((base_price * tax / 100) + license1 / 100) + dealer +
            > charge[/color]

            It would be much simpler if, having read the base price and the license
            (which I presume you are expecting to be percentages) you then
            separately computed the tax *amount* and the license *amount*, then just
            added everything together.

            So, for example, your program might look like this:

            base_price = int(raw_input(. ..))
            tax_rate = int(raw_input(. ..)
            tax_amount = base_price * ((100+tax_amoun t)/...)
            ...
            actual_price = (base_price +
            tax_amount +
            license_amount +
            dealer +
            charge)
            print "Please hand over", actual_price

            Obviously the "..." are the bits you fill in to complete the program.
            Good luck!

            regards
            Steve
            --
            Meet the Python developers and your c.l.py favorites March 23-25
            Come to PyCon DC 2005 http://www.pycon.org/
            Steve Holden http://www.holdenweb.com/

            Comment

            • Bruno Desthuilliers

              #7
              Re: Error!

              Steve Holden a écrit :
              (snip)[color=blue]
              > So, for example, your program might look like this:
              >
              > base_price = int(raw_input(. ..))
              > tax_rate = int(raw_input(. ..)
              > tax_amount = base_price * ((100+tax_amoun t)/...)[/color]
              s/(100+tax_amount )/(100 + tax_rate)/, I guess ?

              Comment

              • Steve Holden

                #8
                Re: Error!

                Bruno Desthuilliers wrote:
                [color=blue]
                > Steve Holden a écrit :
                > (snip)
                >[color=green]
                >> So, for example, your program might look like this:
                >>
                >> base_price = int(raw_input(. ..))
                >> tax_rate = int(raw_input(. ..)
                >> tax_amount = base_price * ((100+tax_amoun t)/...)[/color]
                >
                > s/(100+tax_amount )/(100 + tax_rate)/, I guess ?[/color]

                Oops.

                Let's try

                tax_amount = base_price*(tax _rate/100.0)

                Clearly I was right about simplification being a good idea :-)

                regards
                Steve
                --
                Meet the Python developers and your c.l.py favorites March 23-25
                Come to PyCon DC 2005 http://www.pycon.org/
                Steve Holden http://www.holdenweb.com/

                Comment

                • administrata

                  #9
                  Re: Error!

                  "John Machin" <sjmachin@lexic on.net> wrote in message news:<110756307 0.861085.180680 @g14g2000cwa.go oglegroups.com> ...[color=blue]
                  > administrata wrote:[color=green]
                  > > I'm programming Car Salesman Program.
                  > > It's been "3 days" learning python...[/color]
                  >[color=green]
                  > >From whom or what book or what tutorial?[/color]
                  >[color=green]
                  > > But, i got problem[/color]
                  >
                  > You got problemS. What Jeff & Brian wrote, plus:
                  >
                  > You have "change" instead of "charge".
                  >
                  > You forgot to add in the base price -- "actual price" according to you
                  > comprises only the taxes and fees. Where is your car yard? We'd each
                  > like to order a nice shiny red Ferrari :-)
                  >
                  > Cheers,
                  > John[/color]

                  Thx 4 helps everyone! :)

                  Comment

                  Working...