Skip to content
Advertisement

Using a while loop to output a list after user input

I’m new to python and im attempting for my program to output a the variable “movie genre” vertically once a user enters their name. I plan to use a while loop but keep hitting the error “movie_genre”. And perplexed as to how to proceed.

JavaScript

Advertisement

Answer

You didn’t show error message but if this is your original indentations then problem is that you create movie_genre inside function – so it is local variable which exists only inside function, but rest of code is outside function and it can’t access it. You should move all code inside function or you should keep all code outside function.

I will keep all outside function – so I can remove it.

There are other mistakes and few elements which you could fix

You could keep genders withou inner [] and then you don’t need zip(*...)

JavaScript

You use name in strange way in i = name(..)name is a string and you can’t use it like a function. Maybe you needed input() to ask for selected genreselected = input(...) – but I would do this after displaying genres.

I also don’t know what you want to do with while name. This will run loop forever because you doesn’t change name inside loop. Maybe you need something different – ie. maybe you want to repeate loop until user select correct gender – `while selected not in movie_genre:


Full example

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement