Question 1:

Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5, between 2000 and 3200 (both included). The numbers obtained should be printed in a comma-separated sequence on a single line.

Hints:

1. Consider use range(#begin, #end) method to produce range of values

2. Append each value to list and print using join() function

3. Convert the value to string before appending

4. Only strings have join() function

Solution:

l=[]
for i in range(2000, 3201):
    if (i%7==0) and (i%5!=0):
        l.append(str(i))

print(','.join(l))

 

Discussion:

1. for loop used to process the range() function values between 2000 and 3200

2. used to check whether the value is divisible by 7 but are not a multiple of 5

3. Both condition are true, then only it will be added in the list