-2
PlayerAnswer = easygui.enterbox ("What is" +Figure1+ "+" +Figure2+ "?")

This line of code is not reading, both Figure1 and Figure2 are defined as random variables, and the random module is imported.

Here is how I've defined them at the top of the code:

Figure1 = random.randrange(0,11)
Figure2 = random.randrange(0,11)

The error I get is:

TypeError: cannot concatenate 'str' and 'int' objects**

Here is the coding in context:

for number in range(0,11):
    PlayerAnswer = easygui.enterbox ("What is" +Figure1+ "+" +Figure2+ "?")
    if PlayerAnswer ==(Figure1 + Figure2):
            AdditionAnswers += 1
            easygui.msgbox ("Correct! Your score is "+str(AdditionAnswers))**
2
  • What does it mean for code to read?
    – pppery
    Nov 6, 2015 at 22:16
  • You can't concatenate strings and integers.
    – Peter Wood
    Nov 6, 2015 at 22:54

1 Answer 1

1

You can't add values with types that are of a string and an integer together. In order to make this work properly, you need to convert the two values to strings using the str function, like this:

PlayerAnswer = easygui.enterbox ("What is" + str(Figure1) + "+" + str(Figure2) + "?")
1
  • Thankyou so much! Seems so obvious now haha, thanks for your help :3
    – Char
    Nov 6, 2015 at 22:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.