Python Forum
Problems with printing score of test
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problems with printing score of test
#1
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,
Reply
#2
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))
Reply
#3
Thank you for the help. I will correct my code shortly.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to test the high-score in my Python-game Pluviometer 2 547 Oct-02-2023, 06:55 PM
Last Post: deanhystad
  How to test and import a model form computer to test accuracy using Sklearn library Anldra12 6 3,070 Jul-03-2021, 10:07 AM
Last Post: Anldra12
  How to write test cases for a init function by Unit test in python? binhduonggttn 2 3,067 Feb-24-2020, 12:06 PM
Last Post: Larz60+
  How to write test cases by Unit test for database configuration file? binhduonggttn 0 2,512 Feb-18-2020, 08:03 AM
Last Post: binhduonggttn
  help with keeping score W3BL3Y 2 6,201 Apr-29-2018, 01:12 PM
Last Post: W3BL3Y

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020