【Python编程基础练习】 Python编程基础练习100题学习记录第一期(1~10)
1.此为GitHub项目的学习记录,记录着我的思考,代码基本都有注释。2.可以作为Python初学者巩固基础的绝佳练习,原题有些不妥的地方我也做了一些修正。
3.建议大家进行Python编程时使用英语,工作时基本用英语。
4.6~17题为level1难度,18-22题为level3难度,其余都为level1难度。
项目名称:
100+ Python challenging programming exercises for Python 3
[*]
#!usr/bin/env Python3.9 # linux环境运行必须写上
# -*- coding:UTF-8 -*- # 写一个特殊的注释来表明Python源代码文件是unicode格式的
"""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'''
l1 = []# 建立空列表
for i in range(2000, 3201): # for循环寻找能被7整除但不能被5整除的数字
if (i % 7 == 0) and (i % 5 != 0):
l1.append(str(i)) # 列表里的数据需要是字符串
print(','.join(l1)) # 在一行显示,以逗号隔开
[*]
#!usr/bin/env Python3.9# -*- coding:UTF-8 -*-"""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.'''i = 1result = 1t = int(input('请输入一个数字: '))while i
页:
[1]