0

whats wrong?

when the game ends (i reach 2 points or the system reaches 2 points) i get an error that says: TypeError: Can't convert 'int' object to str implicitly how to fix it? code: import random Systems_ChoiceList = ["Rock" , "Paper" , "Scissors"] my_points = 0 system_points = 0 while True: s_choice = random.choice (Systems_ChoiceList) my_choice = str(input()) my_choice = my_choice.capitalize() if (my_choice == "Rock" or my_choice == "Paper" or my_choice == "Scissors"): print ("You: " + my_choice) print ("System: " + s_choice) if (my_choice == "Rock" and s_choice == "Scissors"): print ("\nYou Won!") my_points += 1 elif (my_choice == "Paper" and s_choice == "Rock"): print ("\nYou Won!") my_points += 1 elif (my_choice == "Scissors" and s_choice == "Paper"): print ("\nYou Won!") my_points += 1 elif (my_choice == "Rock" and s_choice == "Rock"): print ("\nIt's a Draw!") elif (my_choice == "Paper" and s_choice == "Paper"): print ("\nIt's a Draw!") elif (my_choice == "Scissors" and s_choice == "Scissors"): print ("\nIt's a Draw!") else: print ("\nYou Lost...") system_points += 1 else: print ("You can only enter Rock, Paper or Scissors! Run the Systen again in order to play!") if my_points == 2 or system_points == 2: print ("you reached " + my_points + " points!\nSystem reached " + system_points + " points!") break

5th Jul 2020, 12:34 PM
Yahel
Yahel - avatar
4 ответов
+ 4
There is no need to convert output values explicitely. Best option is to use f-string, or this way of using print without convertion or adding spaces to the strings: print ("you reached", my_points, "points!\nSystem reached", system_points, "points!")
5th Jul 2020, 2:59 PM
Lothar
Lothar - avatar
+ 1
thanks !!!
5th Jul 2020, 12:43 PM
Yahel
Yahel - avatar
0
When you are printing result in the end, the function print() is supposed to get only string elements but you are passing int elements as well, convert them first to string and then pass in print function.
5th Jul 2020, 12:39 PM
Lakshay Mittal
Lakshay Mittal - avatar
0
those few last lines. you just need to convert the points variables to strings print('you reached' + str(my_points) + ........)
5th Jul 2020, 12:40 PM
Slick
Slick - avatar