1.此为GitHub项目的学习记录,记录着我的思考,代码基本都有注释。 2.可以作为Python初学者巩固基础的绝佳练习,原题有些不妥的地方我也做了一些修正。 3.建议大家进行Python编程时使用英语。 4.6~17题为level1难度,18-22题为level3难度,其余都为level1难度。 项目名称: 100+ Python challenging programming exercises for Python 3
"""
Please write a program which accepts a string from console and print the characters that have even indexes.
Example: If the following string is given as input to the program:
H1e2l3l4o5w6o7r8l9d
Then, the output of the program should be:
Helloworld
"""
'''Hints: Use list[::2] to iterate a list by step 2.'''
temp = input('Please input:')
l1 = temp[::2]
print(l1)
"""
Please write a program which prints all permutations of [1,2,3]
"""
'''Hints: Use itertools.permutations() to get permutations of list.'''
from itertools import permutations
l1 = [1, 2, 3]
l2 = list(permutations(l1))
print(l2)
"""
Write a program to solve a classic ancient Chinese puzzle:
We count 35 heads and 94 legs among the chickens and rabbits in a farm.
How many rabbits and how many chickens do we have?
"""
'''Hint: Use for loop to iterate all possible solutions.'''
heads = 35
legs = 94
for i in range(heads + 1):
for j in range(heads + 1):
if 2 * i + 4 * j == legs:
print("There are %d chickens and %d rabbits" % (i, j))
"""def solve(num_heads, num_legs):
ns = 'No solutions!'
for i in range(num_heads + 1):
j = num_heads - i
if 2 * i + 4 * j == num_legs:
return i, j
return ns, ns
num_heads = 35
num_legs = 94
solutions = solve(num_heads, num_legs)
print(solutions)"""
好了,这就是Python编程基础练习100题学习记录全十期了,希望大家能够有所收获呀,附上所有链接: 【GitHub】 Python编程基础练习100题学习记录第一期(1~10) 【GitHub】 Python编程基础练习100题学习记录第二期(11~20) 【GitHub】 Python编程基础练习100题学习记录第三期(21~30) 【GitHub】 Python编程基础练习100题学习记录第四期(31~40) 【GitHub】 Python编程基础练习100题学习记录第五期(41~50) 【GitHub】 Python编程基础练习100题学习记录第六期(51~60) 【GitHub】 Python编程基础练习100题学习记录第七期(61~70) 【GitHub】 Python编程基础练习100题学习记录第八期(71~80) 【GitHub】 Python编程基础练习100题学习记录第九期(81~90) 【GitHub】 Python编程基础练习100题学习记录第十期(91~93)
再附上Python常用标准库供大家学习使用: Python一些常用标准库解释文章集合索引(方便翻看)
“学海无涯苦作舟”
|