Ask Question
24 July, 12:12

a. displays the sum of all even numbers between 2 and 100 (inclusive). b. displays the sum of all squares between 1 and 100 (inclusive). c. displays the powers of 2 from 1 up to 256. d. displays the sum of all odd numbers between a and b (inclusive), where a and b are inputs. e. displays the sum of all odd digits of an input. (For example, if the input is 32677, the sum would be 3 + 7 + 7 = 17.) You must achieve each step using a loop.

+5
Answers (1)
  1. 24 July, 15:12
    0
    The program required is in the explanation segment.

    Explanation:

    Program:

    import math

    # a. displays the sum of all even numbers between 2 and 100 (inclusive).

    print ("All even numbers from 2 to 100 inclusive ")

    sum=0

    i=2

    while i<=100:

    if i %2 = =0:

    sum=sum+i

    print (i, end=" ")

    i=i+1

    print ("/nThe sum of all even numbers between 2 and 100 (inclusive) : ", sum);

    #b. displays the sum of all squares between 1 and 100 (inclusive).

    print ("/nAll squares numbers from 1 to 100 inclusive:")

    i=1

    sum=0

    while i<=100:

    print (i*i, end=" ")

    i=i+1

    sum=sum + (i*i)

    print ("/n/nThe sum of all squares between 1 and 100 (inclusive) is : ", sum)

    #c. displays the powers of 2 from 1 up to 256.

    print ("/nAll powers of 2 from 2 * * 0 to 2 * * 8:")

    i=0

    while True:

    p=math. pow (2, i)

    if p>256:

    break

    print ("2 * * ", i," is ", int (p))

    i=i+1

    #d. displays the sum of all odd numbers between a and b (inclusive), where a and b are inputs

    print ("/nCompute the sum of all odd integers between two intgers ")

    a=int (input ("Enter an integer:"))

    b=int (input ("Enter another integer: "))

    count = 0

    temp=a

    sum=0

    while a<=b:

    if a%2!=0:

    print (a, end=" ")

    sum=sum+a

    a=a+1

    print ("/nThe total of the odd numbers from ", temp," to ", b,"is", sum)

    #e. displays the sum of all odd digits of an input. (For example, if the input is 32677, the sum would be 3 + 7 + 7 = 17.)

    print ("/nCompute the sum of the odd digits in an integer ")

    n=int (input ("Enter an integer:"))

    count=0

    sum=0

    temp=n

    while n!=0:

    rem = n%10

    if rem%2!=0:

    sum=sum+rem

    count=count+1

    n=int (n/10)

    print ("Sum of the odd digits is ", sum)

    print ("The total of the odd digits in ", temp," is ", count)
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “a. displays the sum of all even numbers between 2 and 100 (inclusive). b. displays the sum of all squares between 1 and 100 (inclusive). c. ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers