Is there a way to print an int (score) inside of a string without getting an error?
That is the code i currently have, which prints
I get the error
But that wouldn't work because when you get a question right, and use
You would get an error. Unless you use
But then score would equal to "01" and not "1"
1 2 3 4 5 |
score = 0 score = score + 1 print ( "Your score was " ) print (score) print ( " out of 5" ) |
Output:Your score was
1
out of 5
And when i change it to this1 2 3 |
score = 0 score = score + 1 print ( "Your score was " + score + " out of 5" ) |
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 beginning1 |
score = "0" |
1 |
score = score + 1 |
1 |
score = score + "1" |
Self-taught HTML, CSS, Python, and Java programmer