The basic syntax example Python

1, an example of a

Demand: known input function may receive user input and return to the input string, int function string can be converted to an integer. Write a guessing game, a pre-set numbers, gamers enter a number, if equal to a preset number, the player wins, if not equal, suggesting that the player is too big or too small, players have three chances guessing.
implementation while loop as follows:

for the implementation of the following cycle:

2, two exemplary

Requirements: print Pascal's Triangle.

Attachment: the factorial method for Python:

import math
math.factorial(5)     # 5的阶乘

3, Example Three

Demand: Print all prime numbers 2 to 100.

4, Example Four

Requirements: an ordered list of the two merged into a new ordered list.

5, an example of five

Demand: by word flip string. For example: 'i love python' inverted 'python love i'.

6, an example of six

Requirements: find a list of numbers appears only once, and keep the original order.

7, an example seven

Requirements: Find the maximum value in a list.

8, an example of eight

Demand: a program to write, into a digital string, such as '123' 123 into '0.254' is converted to 0.254. Int function is not allowed, float function, the eval function, do not allow any import module.
step1. Character-digital functions:

Step2. where the input is a positive number:

Step3. Processing the input in a negative case has:

Step4. the case of processing the digital input is not:


. STEP5 simple string conversion dictionary:

9, nine examples

Demand: Demand Cartesian product of two lists.

10, an example of ten

Requirements: do not use the number of combinations print Pascal's Triangle.

11, an example of eleven

Demand: Analyzing a four arithmetic parentheses match, for example, 3 * 3 + {[(2-3) * (4 + 5)]} brackets are matched, and 3 * 3 + {[4-6}] of brackets is not matched.

12, an example of twelve

需求:不带括号的四则运算转化为前缀表达式,符号之间由空格分隔。
例如:
1 + 2 => + 1 2
1 + 2 * 3 => + 1 * 2 3

13、示例十三

需求:分别使用递归、循环和生成器求菲波那契数列。
递归方式:

循环方式:

生成器方式:

14、示例十四

需求:写一个函数,实现对整数的排序,默认升序排列,不能使用任何内置函数和第三方库。

15、示例十五

需求:写一个函数,把罗马数字转化为整数,输入为1到3999之间的任意数字。

16、示例十六

需求:写一个函数,求两个字符串的最长公共子串。
例如:输入I love Python和Python is a simple language,输出为Python。

发布了219 篇原创文章 · 获赞 603 · 访问量 129万+

Guess you like

Origin blog.csdn.net/gongxifacai_believe/article/details/94023209