What kind of error do you have? Does the code fail to run (syntax error) or not do what you want it to (semantic error)? More info would make it easier to help you.
I’ll just point out a few issues I noticed, not sure exactly which one is causing your issue but just so you know, your casting a string (Text incased in “” or ‘’) into a string with the str(), you can remove that since its unneeded.
Second, your second input (p2), instead of using the random itself, you prompt the user for input, and prompting them with the message that is the random number it should instead be:
p2 = str(random.randint(1,3)
Now the issue that’s probably causing you the problem with the way the program works is the fact that each if is comparing a variable that is a string (user’s inputs are strings unless casted), to a int, which will always be false, So you need to either change the ints to strings (by encasing them with a “” or ‘’) or cast the variables into int (so p1 needs to become
p1=int(input(’‘1=Rock
2=Scissors
3=Paper
Choose 1, 2 or 3:’’’))
and p2 would become
p2 = random.randint(1, 3)
also the code after the if’s has to be indented (CD removes this indent, you might have that it just doesn’t show)
I would suggest adding a if p1 == 1: print(‘okay it’s 1’) (properly formatted) after you get the input to p1. Then figure out why it’s not printing when you enter a 1. You also have the same problem with p2 (among other issues with that declaration).
Python is dynamically typed and strongly typed. If you’re coming from another language where that’s not the case, it can be confusing. To put it another way, what type of value do you think you’re storing in p1? What type of value are you comparing it to? And for p2, what does the input function do?
Also remember in python (x,y…) is a data type called a tuple, which works like a list (or array in other languages) except its immutable so you can’t change the values. I’m not sure if you want p1 and p2 to be stored as tuples but if you do, then you’ll want to use p1[0] to access the value the user typed. Otherwise you can remove the outermost set of parenthesis on both of your variables.
BTW, are you getting a syntax error popup rather than one logged in the console?
That isn’t a tuple though? Its just a single value wrapped in brackets ().
If you write the line
val = (3)
and then type(val)
it will return int, since this is just a order of operations, which is redundant but also won’t become a tuple (You need to list multiple elements for it to be a tuple)
If you really need a tuple of one element, you can use (1,).
I would recommend using code blocks to format your code, make it easier to read. Use three backticks (on the ~ key) in a row to start a block, then three more to end it. See here for more info.
It’s a fun fact, but also generally part of the problem the OP is experiencing. What type is assigned to the variables and what type are the variables being compared to?
One thing you could think about is adding your information to a dictionary. In python, the dictionary is a key value pair setup where you just reference the one you’re looking for: