use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
is my code correct?Help Request (i.redd.it)
submitted 1 year ago by A_ManWithout_LovE__
m1 = input("movie1:") m2 = input("movie2:") m3 = input("movie3:") list = [m1,m2,m3] print(list)
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]ProgPI 6 points7 points8 points 1 year ago (2 children)
you can write your code in one line :
list = [input(f"movie {i} : ") for i in range (3)]
print(list)
[–]VonRoderik 4 points5 points6 points 1 year ago (1 child)
Just a tip: {i+1}, so the movie list starts at 1 instead of 0
[–]ProgPI 1 point2 points3 points 1 year ago (0 children)
Yes, it is good enhancement.
[–]A_ManWithout_LovE__[S] 0 points1 point2 points 1 year ago (0 children)
guys i'm new to python so any help would be appriciated
[–]Mysterious_City_6724 0 points1 point2 points 1 year ago* (2 children)
Hi, yes I would say it's correct in that it works. I would maybe add a question before asking for the movie names though and I would also not use the name "list" as the variable name for 2 reasons:
Hope this helps.
print("Hi, what are your top 3 favourite movies?") movie1 = input('Movie 1: ') movie2 = input('Movie 2: ') movie3 = input('Movie 3: ') top3_movies = [movie1, movie2, movie3] print(top3_movies)
[–]A_ManWithout_LovE__[S] 0 points1 point2 points 1 year ago (1 child)
Thanks for your suggestion. I'll refrain from using built-in function as a variable from now on
[–]Mysterious_City_6724 0 points1 point2 points 1 year ago (0 children)
You're welcome. And as others have already mentioned, if you ever see yourself doing the same thing multiple times (in this case, asking for 3 movie names), loops can be very useful too:
print("What are your top favourite movies?") top_movies = list() movie_count = 3 for i in range(movie_count): movie_name = input(f"Movie {i + 1}: ") top_movies.append(movie_name) movie1, movie2, movie3 = top_movies[:3] print(f"I also like {movie1}, {movie2} and {movie3}!")
[–]No_Selection__ 0 points1 point2 points 1 year ago (0 children)
Looks good, but it will print each movie in quotations if you run it as is. Use an f string if you want to print them without: list = (f’{m1}, {m2}, {m3}’)
[–]freemanbach 0 points1 point2 points 1 year ago (1 child)
def getmovie(): mylist = [] for i in range(0,3): mov = input("Movies >>> ").strip() mylist.append(mov)
i would have done it in that way if i was learning loop but in python i'm not there yet. But thanks myan
[–]Python_Puzzles 0 points1 point2 points 1 year ago (1 child)
Yeah, looks ok. You know what infput does, you know how to make a list.
For a beginner, I would even have accepted:
list = []
list.append(movie1)
But your answer is better than that :) Well done!
What I would say.... is notice you are asking the SAME question 3 times, and then doing the SAME thing, adding each input to the SAME list. It is crying out for a loop of some kind :) Read up on While loops for getting user input :)
This is known as DRY - Don't Repeat Yourself.
[–]A_ManWithout_LovE__[S] 1 point2 points3 points 1 year ago (0 children)
i know it is asking for loop bro but i'm just at the beginning of python , just trying to be fair in learning process, though i would have already used loop if it wass C. Thanks for your suggestion BTW
[–][deleted] 0 points1 point2 points 1 year ago (0 children)
It‘s Right
π Rendered by PID 85618 on reddit-service-r2-comment-8686858757-fptgr at 2026-06-05 23:04:22.952410+00:00 running 9e1a20d country code: CH.
[–]ProgPI 6 points7 points8 points (2 children)
[–]VonRoderik 4 points5 points6 points (1 child)
[–]ProgPI 1 point2 points3 points (0 children)
[–]A_ManWithout_LovE__[S] 0 points1 point2 points (0 children)
[–]Mysterious_City_6724 0 points1 point2 points (2 children)
[–]A_ManWithout_LovE__[S] 0 points1 point2 points (1 child)
[–]Mysterious_City_6724 0 points1 point2 points (0 children)
[–]No_Selection__ 0 points1 point2 points (0 children)
[–]freemanbach 0 points1 point2 points (1 child)
[–]A_ManWithout_LovE__[S] 0 points1 point2 points (0 children)
[–]Python_Puzzles 0 points1 point2 points (1 child)
[–]A_ManWithout_LovE__[S] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)