Python Forum
Problems with printing score of test - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Problems with printing score of test (/thread-881.html)



Problems with printing score of test - JoeLamond - Nov-11-2016

Hello,

I have been writing a logic test in my program. When the person answers a question correctly the score goes up by 1 point. At the end I want to print the score but I have been experiencing some problems.

When I try this:
print(score + "/3")
It does not work.
Error:
Traceback (most recent call last):   File "/Users/joelamond/Documents/Logic Test.py", line 24, in <module>     print(score + "/3") TypeError: unsupported operand type(s) for +: 'int' and 'str'
When I try this:
print(score,"/3")
It prints but with a space between the number and the slash.
Output:
0 /3
I would like it prints like this:
Output:
0/3
How can I do that?

Thankyou,


RE: Problems with printing score of test - micseydel - Nov-11-2016

You need score to be interpreted as a string. The easy way to do that is
print(str(score) + "/3")
but typically you'll want formatting
print("{}/3".format(score))



RE: Problems with printing score of test - JoeLamond - Nov-11-2016

Thank you for the help. I will correct my code shortly.