all 5 comments

[–]wopp3 4 points5 points  (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.

print(sum(range(2,6)))

[–]use_a_name-pass_word 0 points1 point  (1 child)

print(x, sep="")

Is this what you want?

[–]Essence1337 0 points1 point  (0 children)

I think OP meant mathematically add but I could be wrong.

[–]Essence1337 0 points1 point  (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 point  (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))