一套全面的练习,大家智慧的结晶
大家好,好久不见,我最近在Github上发现了一个好东西,是关于夯实Python基础的100道题,原作者是在Python2的时候创建的,闲来无事,非常适合像我一样的小白来练习
对于每一道题,解法都不唯一,我在这里仅仅是抛砖引玉,希望可以集合大家的智慧,如果哪道题有其他解法,希望可以在评论中留下大家宝贵的意见!每次我会更新10道题,一共会更新10篇,这也算是对我之前的文章一个总结啦,如果没有看到我之前有关Python的小白学习分享的同学们,可以戳下面连接查看哈:
如果大家想要和我联系,可以访问我的个人主页:
好啦,闲话少说,让我们开始今天的刷题之旅吧!
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.
解法一
for i in range(2000,3201): if i%7 == 0 and i%5!=0: print(i,end=',') print("\b")
解法二
numbers = [str(x) for x in range(2000,3201) if (x%7==0) and (x%5!=0)] print (','.join(numbers))
Question 2:
* Write a program which can compute the factorial of a given numbers.The results should be printed in a comma-separated sequence on a single line.Suppose the following input is supplied to t