So, I made this little fun code to review over what I've learned... Btw, this is only a snippet of the full code
player_class = input("Pick a class. Pick a choice between - Duelist,"
"Trap Master, and Gun Doctor")
#The code below is a copy and paste that I hacked to death to make i work with this...
if not re.match('^[1-3]*$', player_class):
print("Error! Only numbers 1 to 3 are allowed!")
if player_class == 1:
print("You picked the Gun Doctor")
elif player_class == 2:
print("You picked the Trap Master")
else:
print("You picked the Assassin")
I was searching for a way to only allow the user to use specific characters, so I googled it, and I got this code...
if not re.match("^[a-z]*$", input_str):
print "Error! Only letters a-z allowed!"
It probably looks similar to a statement that is in the previous code, and yes it is, because I hacked it off stack exchange and pasted it in my code, and then proceed to change the if statement. So instead of
if not re.match("^[a-z]*$", input_str):
I changed the [a-z] to [1-3], and instead of input_str, I changed it into player_class.
Now my problem is, I don't understand it
if not re.match('^[1-3]*, player_class):
I understand that changing the a-z to 1-3 makes it so that I can only choose from 1 to 3, but the rest of the code is weird.. Like why is there a * and an ^ with an ' ... Like, what? Why do I need to put the player_class variable in there to? Can someone help me understand this rather weird piece of code?