+ 1

rock paper scissor

this code get user input of two player how many times they can use paper , rock , scissor and in output I should output what is the maximum score for second one. per time he wins get one score and per time he lose , he will lose one score. why doesn't this code work? numbers = [int(i) for i in input('').split(' ')] def shingedbow(): for i in range(numbers[0]): return "paper" for i in range(numbers[1]): return "rock" for i in range(numbers[2]): return "scissor" def friend(): for i in range(numbers[5]): return "scissor" for i in range(numbers[3]): return "paper" for i in range(numbers[4]): return "rock" n = sum(numbers[0:3]) results1 = [] results2 =[] counter = 0 for i in range(n): results1.append(shingedbow()) results2.append(friend()) def check_rps(a,b): if (a=="rock" and b=="scissor") or (a=="scissor" and b=="paper") or (a=="paper" and b=="rock"): return 1 elif (b=="rock" and a=="scissor") or (b=="scissor" and a=="paper") or (b=="paper" and a=="rock"): return 2 elif (a=="rock" and b=="rock") or (a=="scissor" and b=="scissor") or (a=="paper" and b=="paper"): return 3 return counter #def travers(): counter = 0 for i in results1: check_answer=(check_rps(i,results2[results1.index(i)])) #print(check_answer) if check_answer==1: counter-=1 elif check_answer==2: counter+=1 elif check_answer==3: counter+=0 print(counter)

1st Mar 2022, 11:51 AM
shokin touch
1 Answer
G'day shokin touch reading your code in a Q&A message is crappy, please make a "code bit" so we can run what you have created. You appear to have put a lot of effort in to RPS. However, I cannot see your random generation of the choices, how do you decide which choice each player uses for each round? Your line : check_answer=(check_rps(i,results2[results1.index(i)])) seems to be sending two arguments to your function check_rps() however the first argument should be results1 EDIT: does 👉for i in results1 👈 make i behave as the element of results1? Maybe that wasn't your problem... https://www.sololearn.com/discuss/333866/?ref=app
1st Mar 2022, 7:31 PM
HungryTradie - avatar