Quick actions

cmd+k|ctrl+k

Navigation

Languages

enumerate: excercise

Snippet info

Language

Python

Visibility

public

Author

gustav

Created

2026-07-24T02:20:41.400235Z

Updated

2026-07-24T02:20:41.400235Z

##fundamental concept
#enumerate gives you two things at once on each turn: 
#the position (i) and the content (element).

##Find the position of a specific value
#Imagine you have a list of products
#and you want to know on which shelf (index) "product X" is located.

#productos = ["Manzana", "Banana", "Cerezas", "Dátil"]

#for i, despachi in enumerate(productos):
    #if despachi == "Cerezas":
        #print(f'encontre Cerezas en la posicion {i}!')
        
    #else:
        #print(f'posicion {i}: {despachi} no es Cereza')
        
        
        
opciones = ["Jugar", "Opciones", "Salir"]

for i, elemento in enumerate(opciones):
    numero_opcion = i + 1
    print(f"{numero_opcion}. {elemento}")

INFO