[Tutor] Fw: if/else option for making a choice
ALAN GAULD
alan.gauld at btinternet.com
Mon Feb 18 23:58:59 CET 2013
forwarding to the group.
please use reply all to respond to list messages.
Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/
----- Forwarded Message -----
>From: Niclas Rautenhaus <n.rautenhaus at gmx.de>
>To: 'Alan Gauld' <alan.gauld at btinternet.com>
>Sent: Monday, 18 February 2013, 21:09
>Subject: Re: [Tutor] if/else option for making a choice
>
>Thanks for your corrections :)
>
>Well, first at all I sticked to my book, minor mistakes are my bad, I tried
>to write it on my own.
>
>>This isn't Python code and nothing like it appears in the code you posted
>below. There are several problems with the code above:
>
>
>The typos are a result of my e-mail program, I do know, that these commands
>do not start with a capital letter.
>
>>- You have two (( at the raw_input
>Thanks.
>
>> raw_input is a function so you shouldn't compare it to yes
>That is not the point. I do know so. The result oft he user input (yes or
>no) shall trigger a 'yes' or a 'no" event.
>
>> you don't assign the input value to a variable(although you
> do in the code below so you know you should...)
>The input value is clearly working. I can type in different amounts.
>
>> The Print Leather line makes no sense at all.
>The programm should give me a hint that the 'yes' input has been recogniced.
>
>>Did you try running it? Did you get an error?
>I did'nt get any errors. The programm runs fine.
>
>Trying to clarify what I want to do:
>The programm runs fine. The items (leather, hifi and so on) have set values.
>I
>Think of customizing a car for your needs. What do you want, interior, hifi,
>engine; at each step the configurator asks you what you want to pick.
>So to put it in a nutshell, the programm should ask, whether an option is
>chosen, or not.
>
>Each optional feature (the ones with the set values) shall print a line: "Do
>you want this item?" "Yes or no" and demanding an user input.
>Referring to this user input, the programm adds (ore take it easy, prints
>the item) or skips it.
>
>I appreciate your help,
>
>Niclas
>
>
>
>
>-----Ursprüngliche Nachricht-----
>Von: Tutor [mailto:tutor-bounces+n.rautenhaus=gmx.de at python.org] Im Auftrag
>von Alan Gauld
>Gesendet: Montag, 18. Februar 2013 21:08
>An: tutor at python.org
>Betreff: Re: [Tutor] if/else option for making a choice
>
>
>This isn't Python code and nothing like it appears in the code you posted
>below. There are several problems with the code above:
>
>- print does not start with uppercase P.
>- You have two (( at the raw_input
>- if starts lower case i
>- raw_input is a function so you shouldn't compare it to yes
>- you don't assign the input value to a variable(although you
> do in the code below so you know you should...)
>- you compare to yes but it probably should be "yes" - a string.
>- The Print Leather line makes no sense at all.
>
>If you are going to post code post real code.
>Or else make it clear its pseudo code.
>
>Now on to the code you did post...
>
>> I hope it is clear where my problem is.
>
>Not really.
>Did you try running it? Did you get an error?
>If so what?
>
>> #Car price calculator
>>
>> # Set variables for additional items
>> Leather = (500)
>
>Why in ()? you don;t need them
>
>> int (Leather)
>
>And this does nothing - its already an int - and you ignore the result.
>
>> Clima = (1500)
>> int (Clima)
>> Hifi = (250)
>> int (Hifi)
>> Electrics = (750)
>> int (Electrics)
>> Comfort = (2500)
>> int (Comfort)
>
>See above for all of these.
>
>> print "\t\t\tWelcome to the car price calculator!"
>> print "\t\t\tCredits belong to Niclas Rautenhaus"
>> print "\n\nPlease enter the basic price: "
>> basic = int (raw_input())
>
>Now the last line is what your code above should have looked like.
>
>> # Tax is a percentage of the basic car price Tax = basic * 5 / 100 int
>> (Tax)
>
>The int() gets thrown away but thats probably good because you don't want to
>lose the fractional part of the tax value, which is what int() would do.
>
>> print "\nAdded items:"
>> # Here the user should have the possibility to pick either yes or no
>> print "\n\nLeather",(Leather) print "Clima",(Clima) print "Hifi",
>> (Hifi) print "Electrics", (Electrics)
>> print "Comfort", (Comfort)
>> print "Tax", (Tax)
>
>Again you don't need those parentheses
>
>> # Last step: the picked items shall be summarized print "\n\nTotal
>> grand:", basic + Leather + Clima + Hifi \
>> + Electrics + Comfort + Tax
>>
>> raw_input ("\nPress the enter key to exit!")
>
>Personally I'd have split it at the comma:
>
>print "\n\nTotal grand:", \
> basic + Leather + Clima + Hifi + Electrics + Comfort + Tax
>
>But that's a minor quibble.
>
>Ironically I might also have used parentheses to group the additions, like
>so:
>
>print "\n\nTotal grand:", (basic + Leather +
> Clima + Hifi +
> Electrics + Comfort +
> Tax)
>
>Or perhaps better still put them in a list and used sum()
>
>items = [basic, Leather, Clima, Hifi, Electrics, Comfort, Tax] print
>"\n\nTotal grand:", sum(items)
>
>HTH
>
>--
>Alan G
>Author of the Learn to Program web site
>http://www.alan-g.me.uk/
>
>_______________________________________________
>Tutor maillist - Tutor at python.org
>To unsubscribe or change subscription options:
>http://mail.python.org/mailman/listinfo/tutor
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130218/abf88e8b/attachment-0001.html>
More information about the Tutor
mailing list