[Tutor] if/else option for making a choice

wesley chun wescpy at gmail.com
Tue Feb 19 00:48:08 CET 2013


On Mon, Feb 18, 2013 at 10:22 AM, Niclas Rautenhaus <n.rautenhaus at gmx.de>wrote:

> Hello folks,****
>
> ** **
>
> I would be very pleased if someone is able to help me.****
>
> I wrote a small programm, to calculate the grand total for a car.****
>
> A basic price can be entered. Given that basic price, a tax peercentage is
> calculated and added tot he grand total.****
>
>
> But unfortunately I am stuck with giving the user the choice to select an
> additional option!
> The extra items have got set values, but at the moment they all get
> summarized, but i want to choose.
>
> **
>


greetings Niclas, and welcome to Python! while i'll let the others comment
on your code specifically, i can give some overall suggestions/guidance.

you're trying to create an overall price calculator correct? while it's
straightforward providing a base price, the complexity in your app (and
real life) is the set of options that customers can choose from.

in your situation, i think it would be more "Pythonic" to maintain the
extras as a vector of options and prices. you then loop through those,
prompting the user to enter Yes or No, and add either the cost or zero,
respectively. that will help keep your code less complex as well. you would
just be maintaining a running total until the user is done with all their
selections.

good luck!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"A computer never does what you want... only what you tell it."
    +wesley chun : wescpy at gmail : @wescpy
    Python training & consulting : http://CyberwebConsulting.com
    "Core Python" books : http://CorePython.com
    Python blog: http://wescpy.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130218/da2151ab/attachment.html>


More information about the Tutor mailing list