Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Python function called sumOfEvens which takes one argument, an integer

ID: 3858131 • Letter: C

Question

Create a Python function called sumOfEvens which takes one argument, an integer greater than or equal to 1, and returns the result of adding the even integers between 1 and the value of the given argument (inclusive). This function does not print. You may assume that the argument is valid. Here are some examples of how your function should behave: > > > sumOfEvens (1) > > > sumofEvens (2) > > > sumofEvens (3) > > > sumofEvens (4) > > > sumofEvens (5) > > > sumofEvens (6) 12 > > > sumofEvens (101) 2550 > > > sumofEvens (102) 2652 Create a Python function called productofPowersof10 which takes two arguments, both of which are non-negative integers. For purposes of this problem, let's call the first argument exp1 and the second argument exp2. Your function should compute and return (not print) the product of all powers of 10 from 10^exp1to 10^exp2. Here are some examples of how your function should behave: > > > productOfpowersof 10 (0, 0) 1 > > > productOfPowerOf 10 (1, 1) 10 > > > productOfPowerOf 10 (1, 2)

Explanation / Answer

Problem -1:

def sumOfEvens(n):
   if(n>=1):
       i=1
       sum=0
       while(i<=n):
           if(i%2==0):
               sum=sum+i
           i=i+1
   return sum

Problem-2:

def productOfPowers10(exp1,exp2):
   prod=1
   if(exp1>0 and exp2>0):
       while(exp1 <= exp2):
           prod=prod*(10**exp1)
           exp1=exp1+1
   return prod