TVP

# 100＋Python编程题带你快速上手

100+编程练习帮大家轻松学习Python，春节也要抓紧学习哟~

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

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

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

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:

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):

d[i]=i*i

print d

___________________________________

*Solution 4*

values=raw_input()

l=values.split(",")

t=tuple(l)

print l

print 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

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

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

2023-06-02

2023-06-02

2023-06-02

2023-06-02

2023-06-02

2023-06-02

2023-06-02

2023-06-02

2023-06-02

2023-06-02

2023-06-02

10元无门槛代金券