Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

In python, I want to sum all of the values in a variable.

My code is

x=100

y=200

for i in range(a,b):

  if i%2==1:

    print(i)

When I try to print i value, the output is displaying numbers from 100 to 200. But I wanted the sum of all numbers which is 7500.

1 Answer

0 votes
by (36.8k points)

You can try the below code:

a=100

b=200

sum=0

for i in range(a,b):

    if i % 2 == 1:

        sum+=i

print(sum)

output:

7500

If you are a beginner and want to know more about Python the do check out the python for data science course 

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...