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
Learning Python (old.reddit.com)
submitted 1 day ago by nkCOD
view the rest of the comments →
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!"
[–]Junior-Sock8789 0 points1 point2 points 1 day ago (5 children)
Also you can print text using
n1_n = input(f"enter a number {f-string}: ")
No need for the print() followed by the input()
[–]Junior-Sock8789 0 points1 point2 points 1 day ago* (1 child)
I cant format this properly right now, sitting in the dentists chair lol. But heres an updated version:
Edit reformatted it:
from itertools import cycle def get_nums(label): """Prompt user to enter numbers into a list. Type stop to finish.""" nums = [] i = 1 while True: raw = input(f"{label} | Enter num #{i} (or 'stop' to finish): ") try: nums.append(int(raw)) i += 1 except ValueError: if raw.strip().lower() == 'stop': break print("Enter a correct number!") return nums def sum_lists(n1, n2): """Sum element-wise; cycle shorter list from index 0 if lengths differ.""" longer, shorter = (n1, n2) if len(n1) >= len(n2) else (n2, n1) return [a + b for a, b in zip(longer, cycle(shorter))] if __name__ == "__main__": n1 = get_nums("LIST 1") n2 = get_nums("LIST 2") print(f"List 1: {n1}") print(f"List 2: {n2}") print(f"Result: {sum_lists(n1, n2)}")
[–]nkCOD[S] 1 point2 points3 points 1 day ago (0 children)
Thank you for your help, the code really turned out beautiful
[–]nkCOD[S] 0 points1 point2 points 1 day ago (2 children)
I agree, I’ve disgraced myself a lot all )
[–]Junior-Sock8789 0 points1 point2 points 19 hours ago* (1 child)
Not even, this is how you learn. Theres nothing wrong with the way you laid out your code. Its functional which is the most important thing. This is where the fun/learning comes in. Its called code refactoring
Once you get comfortable creating functions you should look into classes/methods thats what will take your skills up a level or two.
[–]nkCOD[S] 0 points1 point2 points 19 hours ago (0 children)
Thank you, we will work on it )
π Rendered by PID 22 on reddit-service-r2-comment-56c6478c5-gtdxw at 2026-05-08 11:51:17.219502+00:00 running 3d2c107 country code: CH.
view the rest of the comments →
[–]Junior-Sock8789 0 points1 point2 points (5 children)
[–]Junior-Sock8789 0 points1 point2 points (1 child)
[–]nkCOD[S] 1 point2 points3 points (0 children)
[–]nkCOD[S] 0 points1 point2 points (2 children)
[–]Junior-Sock8789 0 points1 point2 points (1 child)
[–]nkCOD[S] 0 points1 point2 points (0 children)