100+Python编程题给你练~(附答案).docx
100+Python编程题给你练(附答案) 整理 | Just 出品 | 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 中非常丰富的各种库、标准包或者更高级的技术 结合数据构造以及算法 来解决复杂的问题。 其次 每题都有问题描绘、提示以及解决方案。大众一定要先独立完成 然后再看参考答案哦 前 25 题中 Q15、2225 都是 Level 1 的难度 Q617 为 Level 2 Q1822 为 Level 3。大众正好利用这五道题学习、稳固一下根底 然后就开场准备挑战自己吧 下面先给出前五道题 其他的题目大众可以在 Github 上看到 Question 1 Level 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. Hints: Consider use range(#begin, #end) method Question 2 Level 1 Question: 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 Hints: In case of input data being supplied to the question, it should be assumed to be a console input. Question 3 Level 1 Question: With a given integral number n, write a program to generate a dictionary that contains (i, i*i) such that is an integral number between 1 and n (both included). and then the program should print the dictionary. Suppose the following input is supplied 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() Question 4 Level 1 Question: Write a program which accepts a sequence of comma-separated numbers from console and generate a list and a tuple which contains every number. Suppose the following input is supplied 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 答案要点 Question 5 Level 1 Question: Define a class which has at least two methods: getString: to get a string from console input printString: to print the string in upper case. Also please include simple test function to test the class methods.Hints: *Solution 1* l for i in range(2000, 3201): if (i%7 0) and (i%5! 0): l.append(str(i)print , .join(l) _ *Solution 2*def fact(x): if x 0: return 1 return x * fact(x - 1) x int(raw_input()print fact(x) _ *Solution 3* n int(raw_input() d dict()for i in range(1,n 1): di i*iprint d _ *Solution 4* values raw_input() l values.split( , ) t tuple(l)print lprint t _ *Solution 5*class InputOutString(object): def _init_(self): self.s def getString(self): self.s raw_input() def printString(self): print self.s.upper() strObj InputOutString() strObj.getString() strObj.printString() Use _init_ method to construct some parameters 更多题目可以查阅 Github 地址 | zhiwehu s:/github /zhiwehu/Python-programming-exercises/blob/master/100%2B%20Python%20challenging%20programming%20exercises.txt 本文为Python大本营原创 转载请微信联络 1092722531。 推荐浏览 女程序员 我负责赚钱养家 老公负责貌美如花