Issue
Evenly Divisible:
Create a function that gets three arguments x,y,z as input and return the number of values in the range between x and y(both x and y are included) and evenly divisible by z.
Sample case:- Sample Input 1 20 2 Sample Output 10
Explanation:
From the limit 1 to 20 the values 2,4,6,810,1214,16,18,20 are evenly divisible by 2,so the total number is evenly divisible by 10.
Solution
If you understand it, you might use list comprehension as well.
def evendiv(x,y,z):
return(len([i for i in range(x, y+1) if i%z==0]))
print(evendiv(2,26,4))
Answered By - Anand Gautam
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.