Joel Goldstick joel.goldstick at gmail.com
Sun Mar 25 15:45:41 CEST 2012

```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: ")
> 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
```