首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

假期怎么提升 Python 技能?100+编程题给你练

整理 | Jane

出品 | Python大本营

春节马上就要到了,怎么能让自己在假期里不掉队?今天,营长给大家准备一个项目: 100+ 编程练习,这些题如果能坚持每天至少完成一道,一定可以帮大家轻松 get Python 的编程技能。目前,这个项目已经获得了 2924 Stars,2468 Forks。

首先,这 100+ 练习题根据难易程度分为三个等级:Level 1、2 和 3。下面对如何定义这三个 Level 进行了说明,大家可以结合自身的学习能力和实践经验进行选择。

Level 1:初级。刚入门 Python 或者正在学一些基础课程的同学们。通常包含 1 到 2 个类或函数的问题都可以解决,甚至答案都可能在一些教材中就能找到。

Level 2:中级。已经系统学习过 Python,并且已经有一定的编程背景的同学们,可以解决包含 3 个及以上类或函数的问题,不过这些答案就在教材找不到了。

Level 3:高级:可以用 Python 中非常丰富的各种库、标准包或更高级的技术,结合数据结构和算法,来解决复杂的问题。

其次,每题都有问题描述、提示和解决方案。大家一定要先独立完成,然后再看参考答案哦~

下面先给出前五道题,其他的题目大家可以在 Github 上看到~

Question1

Level1

Question:

Write a program which will find all such numbers which are divisible by7but arenota multiple of5,

between2000and3200(both included).

The numbers obtained should be printedina comma-separated sequence on a single line.

Hints:

Consider use range(#begin, #end) method

Question2

Level1

Question:

Write a program which can compute the factorial of a given numbers.

The results should be printedina comma-separated sequence on a single line.

Suppose the following inputissupplied to the program:

8

Then, the output should be:

40320

Hints:

In case of input data being supplied to the question, it should be assumed to be a console input.

Question3

Level1

Question:

With a given integral number n, write a program to generate a dictionary that contains (i, i*i) such thatisan integral number between1andn (both included).andthen the program shouldprintthe dictionary.

Suppose the following inputissupplied to the program:

8

Then, the output should be:

{1:1,2:4,3:9,4:16,5:25,6:36,7:49,8:64}

Hints:

In case of input data being supplied to the question, it should be assumed to be a console input.

Consider use dict()

Question4

Level1

Question:

Write a program which accepts a sequence of comma-separated numbersfromconsoleandgenerate a listanda tuple which contains every number.

Suppose the following inputissupplied to the program:

34,67,55,33,12,98

Then, the output should be:

['34','67','55','33','12','98']

('34','67','55','33','12','98')

Hints:

In case of input data being supplied to the question, it should be assumed to be a console input.

tuple() method can convert list to tuple

答案要点:

Question5

Level1

Question:

Define aclasswhichhasatleasttwomethods:

getString: to get a stringfromconsole input

printString: toprintthe stringinupper case.

Also please include simple test function to test theclassmethods.

Hints:

*Solution1*

l=[]

foriinrange(2000,3201):

if(i%7==)and(i%5!=):

l.append(str(i))

print','.join(l)

___________________________________

*Solution2*

deffact(x):

ifx ==:

return1

returnx * fact(x -1)

x=int(raw_input())

printfact(x)

___________________________________

*Solution3*

n=int(raw_input())

d=dict()

foriinrange(1,n+1):

d[i]=i*i

printd

___________________________________

*Solution4*

values=raw_input()

l=values.split(",")

t=tuple(l)

printl

printt

___________________________________

*Solution5*

classInputOutString(object):

def__init__(self):

self.s =""

defgetString(self):

self.s = raw_input()

defprintString(self):

printself.s.upper()

strObj = InputOutString()

strObj.getString()

strObj.printString()

Use __init__ method to construct some parameters

更多题目可以查阅 Github 地址:

作者 | zhiwehu

https://github.com/zhiwehu/Python-programming-exercises/blob/master/100%2B%20Python%20challenging%20programming%20exercises.txt

【完】

热 文推 荐

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20190127A0NLSU00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券