Python编程快速上手_第 2 章 控制流

思维导图

【注解】

  1.控制流语句

  1.1 条件语句[根据条件,执行代码块]

    1.1.1 if语句

    1.1.2 else语句

    1.1.3 elseif语句

  [DEMO](当条件很多的时候,注意条件的顺序)

  

  

  

  

  1.2 循环语句

    1.2.1 while循环语句

    1.2.2 for循环语句

    1.2.3 break语句

    1.2.4 continue语句

  [DEMO](while和for循环可以等价使用)

  

  

  2.导入模块方法

  [DEMO]

  3.函数解析

  [DEMO]

时间: 2024-08-25 05:22:33

Python编程快速上手_第 2 章 控制流的相关文章

Python编程快速上手_第 3 章 函数

思维导图 [DEMO]

python编程快速上手之第10章实践项目参考答案

  本章主要讲了python程序的调试,当程序有BUG或异常的时候,我们如何调试代码找出问题点.其实在本章之前的章节我们做练习的时候都会遇到各种各样的错语和异常,最初当不知道程序哪里出错的情况下不可否认的都使用了print语句进行输出并调试代码.没错print也是调试代码的一种工具,直观简单,便也有缺点,就是调试好后要进行删除,也是件麻烦事,于是就有了本章介绍的assert(断言),logging(日志)以及各种调试工具的出现. 首先来回顾一下python的异常. 一.python常见的异常类型

python编程快速上手之第10章实践项目参考答案(11.11.2)

#!/usr/bin/env python # -*- coding:utf-8 -*- import os import re import urllib import json import socket import urllib.request import urllib.parse import urllib.error # 设置超时 import time timeout = 5 socket.setdefaulttimeout(timeout) class Crawler: # 睡

python编程快速上手之第3章实践项目参考答案

1 #!/usr/bin/env python 2 # coding:utf-8 3 # write by mfyang 4 # collatz.py 5 # 从用户读入一个值,并判断这个值是不是一个int类型的整数,如果不是给出异常提示 6 # 如果这个值是偶数 那么让这个数//2 7 # 如果这个值是奇数 那么让这个数 ×3 + 1 8 # 通过不断调用函数的返回值 并打印这个返回值 直到这个返回值为1 9 10 num = raw_input("please input a number:

python编程快速上手之第8章实践项目参考答案

第8章实践项目之疯狂填词 创建一个一个疯狂填词(Mad Libs),程序,它将读入文本文件,并让用户在该文本文件中出现 ADJECTIVE,NOUN,VERB等单词的地方,加上他们自己的文本. 首先准备一个a.txt的文本文件 程序代码如下: #!/usr/bin/env python3.4 # coding:utf-8 # 8.9.2 import re f1 = open('a.txt','r') strf1 = f1.read() print("原文件内容为:") print(s

python编程快速上手之第18章实践项目参考答案(18.4.1)

import pyautogui, time print('Press Ctrl-C to quit.') try: while True: time.sleep(10) pyautogui.moveRel(1, 0, duration=0.25) time.sleep(10) pyautogui.moveRel(-1, 0, duration=0.25) except KeyboardInterrupt: print('\nDone.')

python编程快速上手之第15章实践项目参考答案(17.7.1)

#! python3 # resizeAndAddLogo.py - Resizes all images in current working directory to fit # in a 300x300 square, and adds catlogo.png to the lower-right corner. import os from PIL import Image os.chdir('C:\\Users\\Administrator\\Python35-32\\test\\ku

python编程快速上手之第13章实践项目参考答案(13.6.1)

import os,PyPDF2 os.chdir('D:\\My Documents') for folderName, subfolders, filenames in os.walk('D:\\My Documents'): for file in filenames: if file.endswith('.pdf'): pdfFile = open(file, 'rb') pdfReader = PyPDF2.PdfFileReader(pdfFile) pdfWriter = PyPD

python编程快速上手之第15章实践项目参考答案(17.7.2)

#! python3 # Import modules and write comments to describe this program. import zipfile, os from PIL import Image from PIL import ImageFile #os.chdir('D:\\My Documents\\') ImageFile.LOAD_TRUNCATED_IMAGES = True for foldername, subfolders, filenames i