Jun-09-2018, 12:16 PM
Is there a way to print an int (score) inside of a string without getting an error?
score = 0 score = score + 1 print("Your score was ") print(score) print(" out of 5")That is the code i currently have, which prints
Output:Your score was
1
out of 5
And when i change it to thisscore = 0 score = score + 1 print("Your score was " + score + " out of 5")I get the error
Error:Traceback (most recent call last):
File "C:\Users\{USER}\Desktop\Python\game.py", line 115, in <module>
print("Congratulations! You scored " + score + " out of 5 points")
TypeError: must be str, not int
Is there anyway to fix this? I thought about changing the score to a string in the beginningscore = "0"But that wouldn't work because when you get a question right, and use
score = score + 1You would get an error. Unless you use
score = score + "1"But then score would equal to "01" and not "1"