llawwehttam Posted December 23, 2009 Posted December 23, 2009 I am using a tutorial to get used to python by makeing simple games. In the tutorial it tells me to 28. if guess == number: 29. guessesTaken = str(guessesTaken) 30. print('Good job, ' + myName + '! You guessed my number in ' + guessesTaken + ' guesses!') Now myName is a str object but guessesTaken is an int. When I run the code in the tutorial (above) I get an error line 31, in print('Good job, ' + PlayerName + '! You guessed my number in ' + guessesTaken + ' guesses!') TypeError: cannot concatenate 'str' and 'int' objects my name for things is slightly different than the tutorial but neither work. How to I get it to display int objects?
llawwehttam Posted December 23, 2009 Author Posted December 23, 2009 sorry i just worked it out. I forgot to guessTaken = str(guessTaken) or something similar had a few typo's in there now. Wow I am suddenly enjoying learning programming!!!
BTCC_Fan Posted December 23, 2009 Posted December 23, 2009 Thats one way of doing it, the other way is to use string manipulation which you should cover later. This is where the code would look like: Code: 28. if guess == number: 29. guessesTaken = str(guessesTaken) 30. print('Good job, ' + myName + '! You guessed my number in ' + '%d' guessesTaken + ' guesses!') 1
mrwITch Posted December 31, 2009 Posted December 31, 2009 I am using a tutorial to get used to python by makeing simple games. ..... Python Python Programming Language -- Official Website and documentation off the Home page Python Documentation Index
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now