Search code examples
python-3.xindexinginfinite

Is there anyway I can generate an infinite list of four strings in python


I have a list of four colors which I want to generate an infinite list such that when I enter a random index, it will show me the color found in that position


Solution

  • number = int(input('write your index here:'))
    color = ['b', 'k', 'g', 'y']
    chosen_color = color[number%len(color)]
    print(chosen_color)
    

    Output:

    write your index here: 98435164
    b