# Python_homework **Repository Path**: chen_ke_715/python_homework ## Basic Information - **Project Name**: Python_homework - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-21 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 思考题 1. 描述什么是标准库、开源模块和自定义模块 - Python的标准库是随着pyhon安装时默认5261自带的库 **函数+模块=标准库** - 开源模块是一种开放型代码,放在官网供人选择使用,如github等。 - 自定义模块则是其他程序员为了更好的实现某种目标,在实际开发中逐渐衍生出来的函数库或副产品,然后将其放在互联网上我们共享。 2. 试回答Python是一种什么样的语言 - 它是一种计算机程序设计语言,是一种解释型脚本语言,是高级编程语言。 # 练习题 ## 课后作业1:利用datetime模块和if语句做一个课程提醒工具,使运行程序能自动打印出你今天是否有课,有什么课程。 ### 代码展示 ``` print ("课程提醒") import datetime temp_time = datetime.datetime.today().weekday() week_time = int(temp_time) print (week_time) if week_time ==1: print ("1-2:东区羽毛球课,3-4三实206网站运营与管理") elif week_time ==2: print("8-9九教203大英,10-11一教204广告心理学") elif week_time ==3: print ("Python二实203") elif week_time ==4: print ("1-2九教306大英,8-9七教104科学技术发展史") elif week_time ==5: print ("1-3七教404毛概,4-5同上毛概实践") else: print ("周末") print ("结束") ``` ### 运行结果 ![image](https://gitee.com/chen_ke_715/python_homework/raw/master/course.JPG) ## 课后作业2:利用random模块和if语句做一个“猜猜小游戏”,使输入自己的“名字”,能随机打印一条关于自己的祝福语。 ### 代码展示 ``` import random if __name__ == '__main__': yourname = input("你好!你的名字是什么?\n"); print (yourname + ",请输入一个数字,送你一个祝福语") random_num = random.randint(1,20) time = 0 while time < 3: num = int(input("请输入你的数字:")) if num == random_num: break; elif num < random_num: print ("你的明天值得期待!") else: print ("努力生活的每一刻都值得怀念!") time = time+1 if time < 3: print ("愿你依然真挚,愿你依然纯粹,愿你依然坚守初心!") else: print ("你觉得最艰难的那一刻就是你涅槃重生的人生转折!") ``` ### 运行结果 ![image](https://gitee.com/chen_ke_715/python_homework/raw/master/guess.JPG) ## 课后作业3:利用for循环和range内置函数打印一个9*9的乘法口诀。 ### 代码展示 ``` print(str(1)+"*"+str(1)+"="+str(1)) for i in range(1,10): print("") for j in range(1,i+1): sum=i*j print(str(i)+"*"+str(j)+"="+str(sum),end="\t") print("") ``` ### 运行结果 ![image](https://gitee.com/chen_ke_715/python_homework/raw/master/multiplication.JPG) ## 课后作业4:教材P10-P11代码运用 ### 代码展示 ``` Python 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license()" for more information. >>> import sys >>> sys.platform 'win32' >>> print(sys.version) 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] >>> import os >>> os.getcwd() 'C:\\Windows\\system32' >>> os.environ environ({'ALLUSERSPROFILE': 'C:\\ProgramData', 'APPDATA': 'C:\\Users\\19654\\AppData\\Roaming', 'ASL.LOG': 'Destination=file', 'COMMONPROGRAMFILES': 'C:\\Program Files\\Common Files', 'COMMONPROGRAMFILES(X86)': 'C:\\Program Files (x86)\\Common Files', 'COMMONPROGRAMW6432': 'C:\\Program Files\\Common Files', 'COMPUTERNAME': 'DESKTOP-3V0N8GC', 'COMSPEC': 'C:\\Windows\\system32\\cmd.exe', 'DRIVERDATA': 'C:\\Windows\\System32\\Drivers\\DriverData', 'HOME': 'C:\\Users\\19654', 'HOMEDRIVE': 'C:', 'HOMEPATH': '\\Users\\19654', 'LOCALAPPDATA': 'C:\\Users\\19654\\AppData\\Local', 'LOGONSERVER': '\\\\DESKTOP-3V0N8GC', 'NUMBER_OF_PROCESSORS': '8', 'ONEDRIVE': 'C:\\Users\\19654\\OneDrive', 'ONEDRIVECONSUMER': 'C:\\Users\\19654\\OneDrive', 'OS': 'Windows_NT', 'PATH': 'C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Intel\\WiFi\\bin\\;C:\\Program Files\\Common Files\\Intel\\WirelessCommon\\;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files\\Git\\cmd;C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR;C:\\Users\\19654\\anaconda3;C:\\Users\\19654\\anaconda3\\Library\\mingw-w64\\bin;C:\\Users\\19654\\anaconda3\\Library\\usr\\bin;C:\\Users\\19654\\anaconda3\\Library\\bin;C:\\Users\\19654\\anaconda3\\Scripts;C:\\Users\\19654\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\19654\\AppData\\Local\\GitHubDesktop\\bin;C:\\PyCharm 2020.1.4\\bin;', 'PATHEXT': '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC', 'PROCESSOR_ARCHITECTURE': 'AMD64', 'PROCESSOR_IDENTIFIER': 'Intel64 Family 6 Model 142 Stepping 11, GenuineIntel', 'PROCESSOR_LEVEL': '6', 'PROCESSOR_REVISION': '8e0b', 'PROGRAMDATA': 'C:\\ProgramData', 'PROGRAMFILES': 'C:\\Program Files', 'PROGRAMFILES(X86)': 'C:\\Program Files (x86)', 'PROGRAMW6432': 'C:\\Program Files', 'PSMODULEPATH': 'C:\\Program Files\\WindowsPowerShell\\Modules;C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules', 'PUBLIC': 'C:\\Users\\Public', 'PYCHARM': 'C:\\PyCharm 2020.1.4\\bin;', 'SESSIONNAME': 'Console', 'SYSTEMDRIVE': 'C:', 'SYSTEMROOT': 'C:\\Windows', 'TEMP': 'C:\\Users\\19654\\AppData\\Local\\Temp', 'TMP': 'C:\\Users\\19654\\AppData\\Local\\Temp', 'USERDOMAIN': 'DESKTOP-3V0N8GC', 'USERDOMAIN_ROAMINGPROFILE': 'DESKTOP-3V0N8GC', 'USERNAME': '19654', 'USERPROFILE': 'C:\\Users\\19654', 'WINDIR': 'C:\\Windows'}) >>> import datetime >>> datetime.date.today() datetime.date(2020, 9, 21) >>> datetime.date.today().day 21 >>> datetime.date.today().month 9 >>> datetime.date,today().year Traceback (most recent call last): File "", line 1, in datetime.date,today().year NameError: name 'today' is not defined >>> datetime.date.today().year 2020 >>> datetime.date.isoformat(datetime.date.today()) '2020-09-21' >>> import time >>> time.strftime("%H:%M") '15:42' >>> time.strftime("%A:%P") Traceback (most recent call last): File "", line 1, in time.strftime("%A:%P") ValueError: Invalid format string >>> time.strftime("%A %P") Traceback (most recent call last): File "", line 1, in time.strftime("%A %P") ValueError: Invalid format string >>> time.strftime("%A %p") 'Monday PM' >>> import html >>> html.escape("This HTML fragment contains a tag.") 'This HTML fragment contains a <script>script</script> tag.' >>> html.unescape("I ♥ Python's &It;standard library>.") "I Python's &It;standard library>." >>> ```