- 5
Write a python program to print the sum of all odd numbers from 1 to 100.
7 Antworten
+ 4
I do that because he is beginner i can do it using one loop but i do this to facilate the code for him
codemonkey
+ 2
a=[]
for i in range(1,101):
if i % 2 == 1:
a.append(i)
sum=0
for j in a:
sum+=j
print("the sum of all odd numbers equal ", sum)
+ 2
codemonkey clarity is more important than efficiency
+ 1
If you know the basics of python you can implement that very easily ,why do you want others to code for you wherearetheavocados ?
Is that going to help you in some assignment? If yes sololearn isn't a place for that ,show your attempt from next time and describe what you really Don't understand instead of ordering others to do it for you
+ 1
P.M. I disagree. Not giving advice is a lot better than giving wrong advice, because you have to unlearn something understood wrong and learn the correct way. That means double the effort. And unlearning is harder than learning new things.
0
Erialdo Meta 🇦🇱 well it can be optimised
but its good enough for anyone to understand it at a glance
he just wrote the cleanest solution a beginner can understand , be it efficient or not
it can be gross for you, but it can be a diamond and help someone else, as the saying goes, "someone's trash may be another one's treasure"