How to find the total of 5 numbers using for and range? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to find the total of 5 numbers using for and range?

6th Mar 2020, 4:58 AM
Entroper
Entroper - avatar
2 Answers
+ 2
sum(n for n in range (1, 6)) This is the most simple way, but involves generator expression. For absolute beginner level you can do it imperative style total = 0 for number in range(1, 6): total += number
6th Mar 2020, 5:53 AM
Tibor Santa
Tibor Santa - avatar
0
l=[] for i in range (5): l[i] = input("items : ") Sum(l)
6th Mar 2020, 6:13 PM
Akbar Ali Quazi
Akbar Ali Quazi - avatar