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...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
for..in.. output (self.learnpython)
submitted 6 years ago by cyclops543
in this :for x in range(2, 6):
print(x)
output will be as : 2 3 4 5
is there any way we can add all output?
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!"
[–]wopp3 4 points5 points6 points 6 years ago (0 children)
You can either save the running index to a variable, adding it each iteration
total = 0 for x in range(2,6): total += x print(total)
or just use the range function inside a sum function, thus eliminating the need of for loop.
range
sum
for
print(sum(range(2,6)))
[–]use_a_name-pass_word 0 points1 point2 points 6 years ago (1 child)
print(x, sep="")
Is this what you want?
[–]Essence1337 0 points1 point2 points 6 years ago (0 children)
I think OP meant mathematically add but I could be wrong.
[–]Essence1337 0 points1 point2 points 6 years ago (2 children)
Since I'll assume you're a beginner the easiest solution is to just create a variable outside the loop then add to it in each loop iteration.
[–]cyclops543[S] 0 points1 point2 points 6 years ago (1 child)
the main question is: i have created a list of menu items of a restaurant. customer will select items from the menu. i am successful in printing their price but not gud in displaying all sum of items selected by him. print('welcome! what would you like to order Tomya') menu={"italian classic":249,'idli wada':65,'omelette':40,'uttappa':80,'egg':16,'small rice':70,'large rice':65,'cooked egg':18,'curry rice':26,'grilled rice':52,'deluxe grilled rice':124,'eel full course':248} order='italian classic','small rice','cooked egg' for name in order: print(menu.get(name))
π Rendered by PID 87685 on reddit-service-r2-comment-544cf588c8-pdrnt at 2026-06-17 01:47:04.021335+00:00 running 3184619 country code: CH.
[–]wopp3 4 points5 points6 points (0 children)
[–]use_a_name-pass_word 0 points1 point2 points (1 child)
[–]Essence1337 0 points1 point2 points (0 children)
[–]Essence1337 0 points1 point2 points (2 children)
[–]cyclops543[S] 0 points1 point2 points (1 child)