100+ Python challenging programming exercises 1
Question 1
Question: 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.
编写一个程序,找出2000到3200之间的所有这些数字,这些数字可以被7整除,但不是5的倍数(都包括在内)。数字以逗号分隔的顺序打印在一行上。
Hints: Consider use range(#begin, #end) method
Solution:
l=[]
for i in range(2000, 3201):
if (i%7==0) and (i%5!=0):
l.append(str(i))
print(','.join(l))
Out:
2002,2009,2016,2023,2037,2044,2051,2058,2072