0

What I'm trying to do is allow the user to enter in the red, green, blue of there color and how many tints they want and saving that into a 2d list. Right now I am just trying to put their rgb value in the list the same number of times they enter for the tint.

So for example they enter r = 255 g = 0 b = 0 numTint = 5

I want to fill the list so it is like this for now: tintList = [(255,0,0), (255,0,0), (255,0,0), (255,0,0), (255,0,0)]

The problem is I'm am new to programming an python so I'm am not quite sure how to do this. I believe you have to use nested loops, but I am not sure how. I would really appreciate any help I can get.

def createColorList(r,g,b, numTint):
    tintList = []
    #fill tintList

    return tintList
1
  • 1
    tintList = [(r,g,b)]*numTint Commented Nov 3, 2014 at 1:03

2 Answers 2

1
def createColorList(r,g,b, numTint):
    tintList = []
    for x in range(0, numTint):
        tintList.append((r,g,b))
    return tintList

But I think Use a class to represent RGB value, maybe a better practice.

class Color(object):
    def __init__(self, red, green, blue, tint):
        self.red = red
        self.green = green
        self.blue = blue
        self.tint = tint

    def somemethod(self):
        pass #you can add some method.
Sign up to request clarification or add additional context in comments.

Comments

0

Just use a list comprehension and range:

return [(r,g,b) for _ in range(numTint)]


In [25]: createColorList(255,0,0,5)
Out[25]: [(255, 0, 0), (255, 0, 0), (255, 0, 0), (255, 0, 0), (255, 0, 0)]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.