Skip to content

Latest commit

 

History

History
 
 

16-Random-Colors-Loop

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
tutorial

16 Random Colors (Loop)

We have created a function that returns a color based on a number between 0 and 3 (for any different number, it will return the color black).

Let's say that we are teachers in a 10 student classroom, and we want to randomly assign ONE color, between red, yellow, blue and green, to EACH student.

(only 1 color per student)

📝 Instructions:

  1. Change the function get_allStudentColors so it returns a list of 10 colors, where each item in the list represents the color assigned to each student.

💡 Hints:

  • You have 10 students, you need the loop to iterate 10 times and add these values to a list.

  • In each iteration, generate a random number between 0 and 3 using the randint() function that we have seen in previous exercises.

  • Use the get_color function in this exercise, to find out what color corresponds to the number obtained.

  • Call (execute) the function get_allStudentColors and print its result in the console.