0

Rock-paper-scissors game

Actually, I am trying to create a Python script that will take a 10 user input(rock/paper/scissors). and the computer will use random. choice fund. to play with the user. and on basis of the user-input , there will be points like user-input and cpu-points. I want the code to stop at when user-points or cpu-points or cpu-points+user-points are equle to 10. Problem: I am getting an error on while loop. here's my code: import random print(''' WELCOME TO THE GAME ''') a = ["rock", "paper", "sicors"] def play(x,y): x = random.choice(a) y = input("Please type your MOVE(rock, paper, sicors) > ") userpoints ="" cpupoints = "" boy = userpoints or cpupoints or userpoints + cpupoints while int(boy) < 11: x = random.choice(a) y = input("Please type your MOVE(rock, paper, sicors) > ") if x == "rock" and y == "paper": userpoints = 0 cpupoints = 1 elif x == "paper" and y == "rock": userpoints = 1 cpupoints = 0 elif x == "sicors" and y == "paper": userpoints = 1 cpupoints = 0 elif x == "paper" and y == "sicors": userpoints = 0 cpupoints = 1 elif x == "rock" and y == "sicors": userpoints = 1 cpupoints = 0 elif x == "sicors" and y == "rock": userpoints = 0 cpupoints = 1 elif x == y: userpoints = 0 cpupoints = 0 else: print("please input a valid Char!") break play(print("here we go:\n"),random.choice(a)) #print("userpoints: "+str(userpoints),"cpu: "+str(cpupoints))

7th Apr 2020, 5:45 PM
lucky thandel
lucky thandel - avatar
13 Respuestas
+ 1
- removed the input request outside while loop. - added or 0 to boy variable. - reduced while condition to 2 - moved last commented print inside the function. because it uses local variables that belong to the function. - incremented boy because while will never stop. write two inputs each one in a separate line i. e: paper rock
7th Apr 2020, 6:42 PM
Bahhaⵣ
Bahhaⵣ - avatar
0
I did some modifications check if that is the desired output. https://code.sololearn.com/cTAy4k2rUXm2/?ref=app
7th Apr 2020, 6:39 PM
Bahhaⵣ
Bahhaⵣ - avatar
0
@Bahha there is still error in line 20
8th Apr 2020, 6:41 AM
lucky thandel
lucky thandel - avatar
0
lucky thandel what error did you get because I just tried it, there is no error. may be you don't know how multiple inputs work in Playground. you have to write each one in new line then submit. example : paper (press enter) rock (press submit) if I keept your 11 inputs you have to write them all then submit. what is the point of boy variable initialization?
8th Apr 2020, 8:27 AM
Bahhaⵣ
Bahhaⵣ - avatar
0
don't mind brother, but I think you have to get it wrong. i have to run it 10 times. then it will print the leaderboard. like, how many user gets as points and how many computer. please help me, I am noob in programming.
8th Apr 2020, 5:10 PM
lucky thandel
lucky thandel - avatar
0
that's not how code playground work. you have to put all inputs at once and submit to get your result. it's not interactive. I know what you want to do but it is not possible here.
8th Apr 2020, 6:06 PM
Bahhaⵣ
Bahhaⵣ - avatar
0
could you please @Bahha do it. PLEASE, beg you, my lord.
9th Apr 2020, 3:07 PM
lucky thandel
lucky thandel - avatar
0
do what? I told you the code is working. I explained how you can try it here.
9th Apr 2020, 3:33 PM
Bahhaⵣ
Bahhaⵣ - avatar
0
umm, i am using count, but there is one more problem. please can u solve this. it says x is not defined, while i have made it a global variable. https://code.sololearn.com/cFFODge1bKPw/#py
9th Apr 2020, 3:54 PM
lucky thandel
lucky thandel - avatar
0
you don't have to make it global. global means that there is a global variable that you want to modify in the function. remove global, since there is no global variable x outside the function. make line 22 like : x = ask_user() ask_user() is returning the value but you didn't store it anywhere. -----+++----- in case you want to use global declare x before the function like : x = " " then it will be modified inside the function.
9th Apr 2020, 4:07 PM
Bahhaⵣ
Bahhaⵣ - avatar
0
you changed your code, so line 22 is no longer relevant. the first code would work. you just had to add x = ask_user() inside while loop
9th Apr 2020, 4:11 PM
Bahhaⵣ
Bahhaⵣ - avatar
0
can please msg me on Discord
9th Apr 2020, 5:36 PM
lucky thandel
lucky thandel - avatar
0
luckythandel#6053 PLEASE!
9th Apr 2020, 5:37 PM
lucky thandel
lucky thandel - avatar