python从100提中抽取10题代码_Python基础练习100题 ( 1~ 10)

本文分享了GitHub上的Python基础100题中的前10题,包括找特定范围内的数、计算阶乘、生成平方数字典等题目,提供了多种解法,并邀请读者分享更多高效解法。
摘要由CSDN通过智能技术生成

一套全面的练习,大家智慧的结晶

大家好,好久不见,我最近在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 the program: 8

Then, the output should be:40320*

解法一

def fact(x):

if x == 0:

return 1

return x * fact(x - 1)

x=int(input())

print(fact(x))

解法二

import math as ma

x=int(input()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值