diff --git "a/data/1.python\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/3.\345\256\211\350\243\205Python/install.json" "b/data/1.python\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/3.\345\256\211\350\243\205Python/install.json" index dea68692b3e37146ddb83b81eae497bc4e0984f4..b6dcf0b1b4bd0400b5d6d02c4be5af351e53f375 100644 --- "a/data/1.python\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/3.\345\256\211\350\243\205Python/install.json" +++ "b/data/1.python\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/3.\345\256\211\350\243\205Python/install.json" @@ -1,19 +1,5 @@ { - "one_line": { - "while True:": [ - "while:" - ], - "target = install.get(ret)": [ - "target = install[ret]" - ], - "if target is None:": [ - "if target is not None:" - ], - "print(\"* {}: {} 系统\".format(p, install[p]['platform']))": [ - "print(\"* {}: {} 系统\".format(p))" - ] - }, - "source": "install.py", + "source": "install.md", "depends": [], "exercise_id": 31, "type": "code_options" diff --git "a/data/1.python\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/3.\345\256\211\350\243\205Python/install.md" "b/data/1.python\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/3.\345\256\211\350\243\205Python/install.md" new file mode 100644 index 0000000000000000000000000000000000000000..982fa292c1d84ee4c21034d1b786b7a70a70b22b --- /dev/null +++ "b/data/1.python\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/3.\345\256\211\350\243\205Python/install.md" @@ -0,0 +1,164 @@ +# Python 安装交互å¼æŸ¥è¯¢ç¨‹åº + +Python 历å²ä¸Šæœ‰å‡ 个é‡è¦çš„版本节点: + +* January 1994,Python1.0 å‘布 +* 2000å¹´10月16日,Python2.0 å‘布 +* 2010å¹´7月3日,Python2.7 å‘布,这是Python2.x的最åŽä¸€ä¸ªç‰ˆæœ¬ï¼ŒPython2.x å’Œ Python3.xä¸å…¼å®¹ +* 2008å¹´12月3日,Python3.0 å‘布,Python3引入多个和Python2.xä¸å…¼å®¹çš„特性,Python 从2.x到3.xçš„è¿ç§»ç»åŽ†äº†æ¯”较长的时间,编程è¯è¨€ç‰ˆæœ¬ä¸å…¼å®¹æœ‰æ—¶å€™ä¼šæ˜¯ä¸ªè‡´å‘½é”™è¯¯ï¼ˆä¾‹å¦‚Perl6),好在Python挺过æ¥äº†ã€‚ +* 2021å¹´10月5å·ï¼ŒPython3.10 å‘布,这是目å‰åˆ°2021年为æ¢æœ€æ–°çš„版本 +* 而最新的开å‘ä¸ç‰ˆæœ¬æ˜¯ Python3.11 + +ä¸åŒå¹³å°å¯¹Python环境的默认支æŒæ˜¯ä¸åŒçš„: + +* Windows å¹³å°æ²¡æœ‰é»˜è®¤å®‰è£… Python +* Linux/Mac å¹³å°å¤§éƒ¨åˆ†é»˜è®¤å®‰è£…了 Python2.7 + +一般建议安装Python3.x 版本进行å¦ä¹ 或开å‘。ä¸åŒå¹³å°çš„安装信æ¯å¦‚下: + +```python +install = { + "Windows": "请下载 Windows 安装包安装:https://www.python.org/downloads/windows/", + "CentOS": "使用yum包管ç†å™¨ï¼Œæ‰§è¡Œå‘½ä»¤ï¼šyum install -y python3", + "Ubuntu": "使用apt-get包管ç†å™¨ï¼Œæ‰§è¡Œå‘½ä»¤ï¼šapt-get install -y python3", + "MacOS": "安装brew包管ç†å™¨ï¼Œç„¶åŽæ‰§è¡Œå‘½ä»¤ï¼š brew install python3", +} +``` + +基于这个信æ¯ï¼Œæˆ‘们å¯ä»¥ç¼–写一个交互å¼Python程åºï¼Œ**è¦æ±‚支æŒç”¨æˆ·æ“作**: + +* åå¤è¾“入平å°å¿«æ·é”®å—符查询ä¸åŒå¹³å°åº”该如何快速安装 Python3.x 版本 +* 按`q`退出查询 + +```python +if __name__ == '__main__': + install = { + "Windows": "请下载 Windows 安装包安装:https://www.python.org/downloads/windows/", + "CentOS": "使用yum包管ç†å™¨ï¼Œæ‰§è¡Œå‘½ä»¤ï¼šyum install -y python3", + "Ubuntu": "使用apt-get包管ç†å™¨ï¼Œæ‰§è¡Œå‘½ä»¤ï¼šapt-get install -y python3", + "MacOS": "安装brew包管ç†å™¨ï¼Œç„¶åŽæ‰§è¡Œå‘½ä»¤ï¼š brew install python3", + } + + shortcut_keys = {} + for platform in install: + key = platform[0].lower() + shortcut_keys[key] = platform + + # TODO(You): 请在æ¤æ·»åŠ Python3.x安装文档交互å¼æŸ¥è¯¢ä»£ç +``` + +以下是交互å¼æ‰§è¡Œçš„æ“ä½œæ ·ä¾‹: + +```bash +请选择安装平å°[w/c/u/m, 按q退出]:w +Windows: 请下载 Windows 安装包安装:https://www.python.org/downloads/windows/ +请选择安装平å°[w/c/u/m, 按q退出]:c +CentOS: 使用yum包管ç†å™¨ï¼Œæ‰§è¡Œå‘½ä»¤ï¼šyum install -y python3 +请选择安装平å°[w/c/u/m, 按q退出]:u +Ubuntu: 使用apt-get包管ç†å™¨ï¼Œæ‰§è¡Œå‘½ä»¤ï¼šapt-get install -y python3 +请选择安装平å°[w/c/u/m, 按q退出]:m +MacOS: 安装brew包管ç†å™¨ï¼Œç„¶åŽæ‰§è¡Œå‘½ä»¤ï¼š brew install python3 +请选择安装平å°[w/c/u/m, 按q退出]:q +``` + +以下选对对`Python3.x安装文档交互å¼æŸ¥è¯¢ä»£ç `的实现<span style="color:red">错误</span>的是? + +## template + +```python +if __name__ == '__main__': + install = { + "Windows": "请下载 Windows 安装包安装:https://www.python.org/downloads/windows/", + "CentOS": "使用yum包管ç†å™¨ï¼Œæ‰§è¡Œå‘½ä»¤ï¼šyum install -y python3", + "Ubuntu": "使用apt-get包管ç†å™¨ï¼Œæ‰§è¡Œå‘½ä»¤ï¼šapt-get install -y python3", + "MacOS": "安装brew包管ç†å™¨ï¼Œç„¶åŽæ‰§è¡Œå‘½ä»¤ï¼š brew install python3", + } + + shortcut_keys = {} + for platform in install: + key = platform[0].lower() + shortcut_keys[key] = platform + + while True: + ret = input("请选择安装平å°[w/c/u/m, 按q退出]:") + platform = shortcut_keys.get(ret) + + if ret == 'q': + break + + if platform is None: + print("ä¸æ”¯æŒçš„å¹³å°") + continue + + doc = install.get(platform) + print(f"{platform}: {doc}") +``` + +## ç”案 + +```python +while True: + ret = input("请选择安装平å°[w/c/u/m, 按q退出]:") + platform = shortcut_keys.get(ret) + + if ret == 'q': + break + + if platform is None: + print("ä¸æ”¯æŒçš„å¹³å°") + break + + doc = install.get(platform) + print(f"{platform}: {doc}") +``` + +## 选项 + +### guard æ¨¡å¼ + +```python +while True: + ret = input("请选择安装平å°[w/c/u/m, 按q退出]:") + if ret == 'q': + break + platform = shortcut_keys.get(ret) + if platform is None: + print("ä¸æ”¯æŒçš„å¹³å°") + else: + doc = install.get(platform) + print(f"{platform}: {doc}") +``` + +### if-elseæ¨¡å¼ + +```python +while True: + ret = input("请选择安装平å°[w/c/u/m, 按q退出]:") + if ret != 'q': + platform = shortcut_keys.get(ret) + if platform is not None: + doc = install.get(platform) + print(f"{platform}: {doc}") + else: + print("ä¸æ”¯æŒçš„å¹³å°") + else: + break +``` + +### 优先æ£æ–‡é€»è¾‘ + +```python +while True: + ret = input("请选择安装平å°[w/c/u/m, 按q退出]:") + platform = shortcut_keys.get(ret) + + if ret == 'q': + break + + if platform is None: + print("ä¸æ”¯æŒçš„å¹³å°") + continue + + doc = install.get(platform) + print(f"{platform}: {doc}") +``` diff --git "a/data/1.python\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/3.\345\256\211\350\243\205Python/install.py" "b/data/1.python\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/3.\345\256\211\350\243\205Python/install.py" index e53568a3d1a20578149202c75e4f8647d2d80325..2572ea6257f6db88adff1c7ea0d5d09cedf04b81 100644 --- "a/data/1.python\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/3.\345\256\211\350\243\205Python/install.py" +++ "b/data/1.python\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/3.\345\256\211\350\243\205Python/install.py" @@ -1,38 +1,31 @@ # -*- coding: UTF-8 -*- # 作者:幻ç°é¾™ -# æ ‡é¢˜ï¼šå®‰è£…Python +# æ ‡é¢˜ï¼šPython 安装交互å¼æŸ¥è¯¢ç¨‹åº # æ述:交互å¼æ示程åºï¼Œç”¨æˆ·é€‰æ‹©å¯¹åº”å¹³å°åŽï¼Œèƒ½æ£ç¡®è¾“出对应平å°ä¸Šçš„安装包下载连接 -def test(): +if __name__ == '__main__': install = { - "w": { - "platform": "Window", - "desc": "请下载 Windows 安装包安装:https://www.python.org/downloads/windows/" - }, - "l": { - "platform": "Linux", - "desc": "请下载 Linux çš„ Python æºç 安装:https://www.python.org/downloads/source/", - }, - "m": { - "platform": "MacOS", - "desc": "请下载 Mac 的安装包:https://www.python.org/downloads/macos/,或者使用 brew install python 安装", - } + "Windows": "请下载 Windows 安装包安装:https://www.python.org/downloads/windows/", + "CentOS": "使用yum包管ç†å™¨ï¼Œæ‰§è¡Œå‘½ä»¤ï¼šyum install -y python3", + "Ubuntu": "使用apt-get包管ç†å™¨ï¼Œæ‰§è¡Œå‘½ä»¤ï¼šapt-get install -y python3", + "MacOS": "安装brew包管ç†å™¨ï¼Œç„¶åŽæ‰§è¡Œå‘½ä»¤ï¼š brew install python3", } - print("Python å¯ä»¥åœ¨å…¨å¹³å°ä¸Šå®‰è£…,例如:") - for p in install: - print("* {}: {} 系统".format(p, install[p]['platform'])) + shortcut_keys = {} + for platform in install: + key = platform[0].lower() + shortcut_keys[key] = platform while True: - ret = input("请选择安装平å°[w/l/m]:") - target = install.get(ret) - if target is None: - print("ä¸æ”¯æŒçš„å¹³å°") - else: - print("安装平å°ï¼š{}".format(target['platform'])) - print("安装说明:{}".format(target['desc'])) + ret = input("请选择安装平å°[w/c/u/m, 按q退出]:") + platform = shortcut_keys.get(ret) + + if ret == 'q': break + if platform is None: + print("ä¸æ”¯æŒçš„å¹³å°") + continue -if __name__ == '__main__': - test() + doc = install.get(platform) + print(f"{platform}: {doc}")