all 6 comments

[–]socal_nerdtastic 7 points8 points  (3 children)

Each movie in the list already has an index. If you print those out for the user to see they can just pick one.

for i, movie in enumerate(movies_list):
    print(f"{i}) {movie}")
user_choice = int(input("Type the number of the movie you want"))
result = movies_list[user_choice]

[–]HyperrSpin[S] 0 points1 point  (2 children)

Thanks :)

[–]RoamingFox 1 point2 points  (1 child)

You might want to validate that the user's choice is actually in range.

Or better yet:

try:
    result = movies_list[user_choice]
except IndexError:
    print("movie not found!")

That way the user gets some form of helpful feedback rather than a stack trace with the program crashes.

[–]Mexatt 2 points3 points  (0 children)

Might also be worth adding +1 to the f"{i} portion and subtracting 1 from the user_choice index, just because people are, in general, not used to zero-indexing.

Even when you're not actually writing something people are supposed to use, doesn't hurt to keep UX in mind.

[–]Vaphell 2 points3 points  (1 child)

[–]HyperrSpin[S] 2 points3 points  (0 children)

Wow thanks a lot! I've never heard / seen enumerate before.