Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > [noob] Error!

Reply
Thread Tools

[noob] Error!

 
 
administrata
Guest
Posts: n/a
 
      02-04-2005
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 "Destination 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...
 
Reply With Quote
 
 
 
 
Jeff Shannon
Guest
Posts: n/a
 
      02-05-2005
administrata wrote:

> Write a Car Salesman program [...]


This sounds like homework, and we generally try to avoid solving
peoples' homework problems for them, but I can offer a suggestion.

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


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

 
Reply With Quote
 
 
 
 
Brian van den Broek
Guest
Posts: n/a
 
      02-05-2005
administrata said unto the world upon 2005-02-04 17:59:
> 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 "Destination 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...


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

 
Reply With Quote
 
John Machin
Guest
Posts: n/a
 
      02-05-2005

administrata wrote:
> I'm programming Car Salesman Program.
> It's been "3 days" learning python...


>From whom or what book or what tutorial?


> But, i got problem


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

 
Reply With Quote
 
administrata
Guest
Posts: n/a
 
      02-05-2005
"John Machin" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed) roups.com>...
> administrata wrote:
> > I'm programming Car Salesman Program.
> > It's been "3 days" learning python...

>
> >From whom or what book or what tutorial?

>
> > But, i got problem

>
> 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


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

can you modify actual_price?

actual_price = (((base_price * tax / 100) + license1 / 100) + dealer +
charge
 
Reply With Quote
 
Steve Holden
Guest
Posts: n/a
 
      02-05-2005
administrata wrote:

> "John Machin" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed) roups.com>...
>
>>administrata wrote:
>>
>>>I'm programming Car Salesman Program.
>>>It's been "3 days" learning python...

>>
>>>From whom or what book or what tutorial?

>>
>>
>>>But, i got problem

>>
>>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

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

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

> can you modify actual_price?
>
> actual_price = (((base_price * tax / 100) + license1 / 100) + dealer +
> charge


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_amount)/...)
...
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/
 
Reply With Quote
 
Steve Holden
Guest
Posts: n/a
 
      02-05-2005
Bruno Desthuilliers wrote:

> Steve Holden a écrit :
> (snip)
>
>> 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_amount)/...)

>
> s/(100+tax_amount)/(100 + tax_rate)/, I guess ?


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/
 
Reply With Quote
 
Bruno Desthuilliers
Guest
Posts: n/a
 
      02-05-2005
Steve Holden a écrit :
(snip)
> 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_amount)/...)

s/(100+tax_amount)/(100 + tax_rate)/, I guess ?
 
Reply With Quote
 
administrata
Guest
Posts: n/a
 
      02-06-2005
"John Machin" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed) roups.com>...
> administrata wrote:
> > I'm programming Car Salesman Program.
> > It's been "3 days" learning python...

>
> >From whom or what book or what tutorial?

>
> > But, i got problem

>
> 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


Thx 4 helps everyone!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments