Jump to content

Recommended Posts

Posted

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?

Posted

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!!!

Posted

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!')

  • Thanks 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...