Please have it written in python Write programs with loops t

Please have it written in python.

Write programs with loops that compute The sum of all even numbers between 2 and 100 (inclusive). The sum of all squares between 1 and 100 (inclusive). All powers of 2 from 2 degree up to 2^20. The sum of all odd numbers between a and b (inclusive), where a and b are user inputs. The sum of all odd digits of an input. (For example, if the input is 32677, the sum would be 3 + 7 + 7 = 17.)

Solution

A) sum of even numbers from 1 to 100:

sum=0
#question :a) sum of all even numbers
for i in range(0,101,2):
sum=sum+i
  
print \'Sum of all even numbers :\'
print(sum)

B) Sum of all squares between 1 to 100 :


sum=0
#question b) sum of all squares
for i in range(1,101,1):
for j in range(0, 11, 1):
if j*j==i:
sum=sum+i
  
print \'Sum of all squares :\'
print(sum)

  

C) Sum of all powers of 2 from power 0 to 20:


#question :c)sum of all powers of 2
sum=0
j=1
for i in range(0,21,1):
j=j*2
sum=sum+j
print \'\ Sum of all powers of 2 from power 0 to 20 :\'
print sum

D) Sum of all odd numbers between range a and b

#question :d)sum of all odd numbers between a and b
a= input(\"Enter a:\")
b= input(\"Enter b:\")
sum=0;
for i in range(a,b+1,1):
if i%2!=0:
sum= sum+i
print \"\ Sum of all odd numbers between a to b :\"
print sum

steps to do E:

num=> number that user enters to find sum of odd digits

while num!=0

i = num% 10

if i % 2 == 1

then sum = sum +i

num= num%10

Please have it written in python. Write programs with loops that compute The sum of all even numbers between 2 and 100 (inclusive). The sum of all squares betwe
Please have it written in python. Write programs with loops that compute The sum of all even numbers between 2 and 100 (inclusive). The sum of all squares betwe

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site