Python - Rock Paper Scissors - Include Input User Name and Score Counter -


i'm trying write easy version of rock paper scissors in python 3 elementary-middle school aged kids understand , reproduce.

besides basic game, want incorporate option them input names player1 , player2, using %s program print out. keep getting error in o/p:

player 1 name: me player 2 name: %s, choose? rock (1), paper (2), or scissors(3)? **traceback (most recent call last):   file "c:/users/xyz/pycharmprojects/rps/scorekeeping.py", line 11, in <module>     print("%s, choose? rock (1), paper (2), or scissors(3)?") % player1 typeerror: unsupported operand type(s) %: 'nonetype' , 'str'** 

i'm trying include score counter updates every round (player1 vs player2). resets 0 per round win/tie/lose.

please me see code went wrong. thanks!


player1 = input("player 1 name: ") player2 = input("player 2 name: ")  while 1:      player1score = 0     player2score = 0      print("%s, choose? rock (1), paper (2), or scissors(3)?") % player1      choice1 = input("> ")      print("%s, choose? rock (1), paper (2), or scissors(3)?") % player2      choice2 = input("> ")      if choice1 == choice2 :         print("its's tie.")     elif choice1 - choice2 == 1 or choice2 - choice1 == 2 :         print("%s wins.") % player1         score1 = score1 + 1     else:         print("%s wins.") % player2         score2 = score2 + 1      print("%s: %d points. %s: %d points.") % (player1, score1, player2, score2) 

you're trying format return value of print function. instead, format string you're printing, try:

print("%s, choose? rock (1), paper (2), or scissors(3)?" % player1) 

for first statement, example. formatting should occur inside parenthesis.

in order convert input value integer, try:

choice1 = int(input("> ")) 

currently, you're resetting score 0 @ start of while loop. stop score counters resetting, put the

player1score = 0 player2score = 0 

before while loop.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -