[Tutor] Question about input
akazmi001 at gmail.com
Sun Mar 25 17:52:25 CEST 2012
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.
On Sun, Mar 25, 2012 at 9:45 AM, Joel Goldstick <joel.goldstick at gmail.com>wrote:
> 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
> > on a Mac with Python 3.2.
> > In the second chapter, the book gives sample code that shows how a
> > 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
> > a sum, I understand that is the mistake in the code. However, when I run
> > it shows:
> > Grand Total: 111Manhattan Apartment: 111Private Jet Rental: 111Gifts:
> > 111Dining Out: 111Staff (butlers, chef, driver, assistant): 111Personal
> > 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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor