There is a list: a = [1,2,3,4,5] I enter the ordinal number of the element from the keyboard: c = int (input ("Vvedi nomer")) then I start the cycle: for i, ii in enumerate (a): how to access any of the list items?
1 answer
It is obvious that you yourself answered your question:
a = [1,2,3,4,5] for i, ii in enumerate(a): print(a[i]) c = int(input("Введите номер:")) try: print(a[c]) except Exception as exc: print(str(exc)) - onein your example,
a[i] is iiyou can directlyii(having come up with the best possible name), instead of using an index. You can simply:print(exc)instead ofprint(str(exc)). - jfs - @jfs, thanks for the clarification, that's it. - user3416803
|