0

How can i place the desired colors in a list to access them by index in the drawing loop?

Is their any other way to code this program to prevent repeating the same code and place the desired color in a list to access them by index? I am stuck here please help Thank you https://code.sololearn.com/c3tRvRd5zJZ0/?ref=app

1st Dec 2020, 9:40 PM
Mark G. Ghrayeb
Mark G. Ghrayeb - avatar
2 Réponses
+ 2
There are definitely other ways. Here I have placed each group of arguments in a tuple and placed all those tuples in a tuple. (You can just as easily use list if you need them to be mutable) Then I loop over the tuple of tuples of arguments and then use the * operator to unpack the arguments in the call to the function. octagons = ((0.00,200.00,'red','yellow'), (105.00,200.00,'blue','grey'), (178.00,124.00,'brown','orange'), (178.00,18.0,'green','pink'), (105.00,-58.00,'orange','black'), (0.00,-58.00,'purple','cyan'), (-73.00,18.00,'cyan','purple'), (-73.00,124.00,'yellow','red')) for octagon in octagons: octagonshape(*octagon) You can also use their indices if you wish.
1st Dec 2020, 11:02 PM
ChaoticDawg
ChaoticDawg - avatar
0
How can i use the list to put the colors if you please can help me and access them by index
8th Dec 2020, 10:59 AM
Mark G. Ghrayeb
Mark G. Ghrayeb - avatar