[Tutor] Question about input
joel.goldstick at gmail.com
Sun Mar 25 18:06:11 CEST 2012
On Sun, Mar 25, 2012 at 11:52 AM, Asif Kazmi <akazmi001 at gmail.com> wrote:
> The odd thing is that the same code runs perfectly in the Mac terminal, but
> incorrectly in Komodo Edit. In the latter, the input prompts are somehow
> being included into the variables themselves somehow due to the way Komodo
> Thanks for the help. I've just taken to running the code in the Mac terminal
> which is working great.
Are you sure that you are running python 3.x in each environment? I'm
not familiar with Komodo, so I can't help you there, but in python
v2.x input attempts to evaluate the values you enter. raw_input, on
the other hand returns your data as a string. In python 3, input was
removed and raw_input's name was changed to input.
See if you have two different versions of python on your system.
> On Sun, Mar 25, 2012 at 9:45 AM, Joel Goldstick <joel.goldstick at gmail.com>
>> On Sun, Mar 25, 2012 at 1:31 AM, Asif Kazmi <akazmi001 at gmail.com> wrote:
>> > Hello,
>> > I'm going through Python Programming for the Absolute Beginner, 3rd
>> > edition,
>> > on a Mac with Python 3.2.
>> > In the second chapter, the book gives sample code that shows how a
>> > logical
>> > error can occur:
>> > # Trust Fund Buddy - Bad
>> > # Demonstrates a logical error
>> > print(
>> > """
>> > Trust Fund Buddy
>> > Totals your monthly spending so that your trust fund doesn't run out
>> > (and you're forced to get a real job).
>> > Please enter the requested, monthly costs. Since you're rich, ignore
>> > pennies
>> > and use only dollar amounts.
>> > """
>> > )
>> > car = input("Lamborghini Tune-Ups: ")
>> > rent = input("Manhattan Apartment: ")
>> > jet = input("Private Jet Rental: ")
>> > gifts = input("Gifts: ")
>> > food = input("Dining Out: ")
>> > staff = input("Staff (butlers, chef, driver, assistant): ")
>> > guru = input("Personal Guru and Coach: ")
>> > games = input("Computer Games: ")
>> > total = car + rent + jet + gifts + food + staff + guru + games
>> > print("\nGrand Total:", total)
>> > input("\n\nPress the enter key to exit.")
>> > This program should show the inputted numbers as a concatenation rather
>> > than
>> > a sum, I understand that is the mistake in the code. However, when I run
>> > it,
>> > it shows:
>> > Grand Total: 111Manhattan Apartment: 111Private Jet Rental: 111Gifts:
>> > 111Dining Out: 111Staff (butlers, chef, driver, assistant): 111Personal
>> > Guru
>> > and Coach: 111Computer Games: 111
>> > It appears to be adding the input prompt as part of the variables?
>> > except
>> > for car? What am I missing?
>> > Thanks,
>> > Asif
>> > _______________________________________________
>> > Tutor maillist - Tutor at python.org
>> > To unsubscribe or change subscription options:
>> > http://mail.python.org/mailman/listinfo/tutor
>> Input returns a string in python 3. So you are doing something like
>> '1' + '1' ... etc which will concatinate the strings. Test it out by
>> typing in something other than a number for your inputs.
>> Once you get that worked out, see what your code produces.
>> Joel Goldstick
More information about the Tutor