-3

I have a list called colors and I want a player to pick 4 colors and then I want them to be saved to a variable after the player has chosen these colors this is my code so far I cannot figure out how to make the 4 colors that the player has chosen to become a variable.

colors = ['R','Y','G','B','P','O']

print ("player 1 Create a 4 color code using", colors)
print "player 2 look away!!"
p1code = raw_input(">>> ")

if p1code == len(colors):
    print "i got the code now!"
vvvvv
  • 25,404
  • 19
  • 49
  • 81
Tyrell
  • 896
  • 7
  • 15
  • 26
  • `len(colors)` is 6, while `p1code` is a string from the user; you might want to think a bit more about what you're trying to achieve before putting it to code. – Steve Nov 07 '17 at 16:34

1 Answers1

0

First, you need brackets in some of your print calls and you want input rather than raw_input, if you're using Python 3.

colors = ['R','Y','G','B','P','O']

print("player 1 Create a 4 color code using", colors)
print("player 2 look away!!")
p1code = input(">>> ")

if p1code == len(colors):
    print("i got the code now!")

Otherwise, with Python 2.x, you don't need brackets, and it will probably help you avoid bugs if you're consistent (currently on your first print line you also print the brackets ('player 1 Create a 4 color code using', ['R', 'Y', 'G', 'B', 'P', 'O']):

colors = ['R','Y','G','B','P','O']

print "player 1 Create a 4 color code using", colors
print "player 2 look away!!"
p1code = raw_input(">>> ")

if p1code == len(colors):
    print "i got the code now!"

Secondly: You have stored the four colours in p1code. When I run the above code:

player 1 Create a 4 color code using ['R', 'Y', 'G', 'B', 'P', 'O']
player 2 look away!!

RBGY #what I entered

In [9]: p1code
Out[9]: 'RBGY'

Thus you can see the string 'RBGY' is stored in the variable p1code.

toonarmycaptain
  • 2,093
  • 2
  • 18
  • 29