###### tags: `Python勉強会` # Python勉強会 第4回 課題 :::info **<第4回Web会議日程>** 2024年02月21日(水) 19:00から **<第4回の自習範囲>** **【Pythonチュートリアル】**  https://docs.python.org/ja/3/tutorial/index.html [6. モジュール](https://docs.python.org/ja/3/tutorial/modules.html)  [6.1. モジュールについてもうすこし](https://docs.python.org/ja/3/tutorial/modules.html#more-on-modules)   [6.1.1. モジュールをスクリプトとして実行する](https://docs.python.org/ja/3/tutorial/modules.html#executing-modules-as-scripts)   [6.1.2. モジュール検索パス](https://docs.python.org/ja/3/tutorial/modules.html#the-module-search-path)   [6.1.3. "コンパイル" された Python ファイル](https://docs.python.org/ja/3/tutorial/modules.html#compiled-python-files)  [6.2. 標準モジュール](https://docs.python.org/ja/3/tutorial/modules.html#standard-modules)  [6.3. dir() 関数](https://docs.python.org/ja/3/tutorial/modules.html#the-dir-function)  [6.4. パッケージ](https://docs.python.org/ja/3/tutorial/modules.html#packages)   [6.4.1. パッケージから * を import する](https://docs.python.org/ja/3/tutorial/modules.html#importing-from-a-package)   [6.4.2. パッケージ内参照](https://docs.python.org/ja/3/tutorial/modules.html#intra-package-references)   [6.4.3. 複数ディレクトリ中のパッケージ](https://docs.python.org/ja/3/tutorial/modules.html#packages-in-multiple-directories) [7. 入力と出力](https://docs.python.org/ja/3/tutorial/modules.html)  [7.1. 出力を見やすくフォーマットする](https://docs.python.org/ja/3/tutorial/inputoutput.html#fancier-output-formatting)   [7.1.1. フォーマット済み文字列リテラル](https://docs.python.org/ja/3/tutorial/inputoutput.html#formatted-string-literals)   [7.1.2. 文字列の format() メソッド](https://docs.python.org/ja/3/tutorial/inputoutput.html#the-string-format-method)   [7.1.3. 文字列の手作業でのフォーマット](https://docs.python.org/ja/3/tutorial/inputoutput.html#manual-string-formatting)   [7.1.4. 古い文字列書式設定方法](https://docs.python.org/ja/3/tutorial/inputoutput.html#old-string-formatting)  [7.2. ファイルを読み書きする](https://docs.python.org/ja/3/tutorial/inputoutput.html#reading-and-writing-files)   [7.2.1. ファイルオブジェクトのメソッド](https://docs.python.org/ja/3/tutorial/inputoutput.html#methods-of-file-objects)   [7.2.2. json による構造化されたデータの保存](https://docs.python.org/ja/3/tutorial/inputoutput.html#saving-structured-data-with-json) [10. 標準ライブラリミニツアー](https://docs.python.org/ja/3/tutorial/stdlib.html)  [10.1. OSへのインターフェース](https://docs.python.org/ja/3/tutorial/stdlib.html#operating-system-interface)  [10.2. ファイルのワイルドカード表記](https://docs.python.org/ja/3/tutorial/stdlib.html#file-wildcards)  [10.3. コマンドライン引数](https://docs.python.org/ja/3/tutorial/stdlib.html#command-line-arguments)  [10.4. エラー出力のリダイレクトとプログラムの終了](https://docs.python.org/ja/3/tutorial/stdlib.html#error-output-redirection-and-program-termination)  [10.5. 文字列のパターンマッチング](https://docs.python.org/ja/3/tutorial/stdlib.html#string-pattern-matching)  [10.6. 数学](https://docs.python.org/ja/3/tutorial/stdlib.html#mathematics)  [10.7. インターネットへのアクセス](https://docs.python.org/ja/3/tutorial/stdlib.html#internet-access)  [10.8. 日付と時刻](https://docs.python.org/ja/3/tutorial/stdlib.html#dates-and-times)  [10.9. データ圧縮](https://docs.python.org/ja/3/tutorial/stdlib.html#data-compression)  [10.10. パフォーマンスの計測](https://docs.python.org/ja/3/tutorial/stdlib.html#performance-measurement)  [10.11. 品質管理](https://docs.python.org/ja/3/tutorial/stdlib.html#quality-control)  [10.12. バッテリー同梱](https://docs.python.org/ja/3/tutorial/stdlib.html#batteries-included) [11. 標準ライブラリミニツアー --- その 2](https://docs.python.org/ja/3/tutorial/stdlib2.html)  [11.1. 出力のフォーマット](https://docs.python.org/ja/3/tutorial/stdlib2.html#output-formatting)  [11.2. 文字列テンプレート](https://docs.python.org/ja/3/tutorial/stdlib2.html#templating)  [11.3. バイナリデータレコードの操作](https://docs.python.org/ja/3/tutorial/stdlib2.html#working-with-binary-data-record-layouts)  [11.4. マルチスレッディング](https://docs.python.org/ja/3/tutorial/stdlib2.html#multi-threading)  [11.5. ログ記録](https://docs.python.org/ja/3/tutorial/stdlib2.html#logging)  [11.6. 弱参照](https://docs.python.org/ja/3/tutorial/stdlib2.html#weak-references)  [11.7. リスト操作のためのツール](https://docs.python.org/ja/3/tutorial/stdlib2.html#tools-for-working-with-lists)  [11.8. 10 進浮動小数演算](https://docs.python.org/ja/3/tutorial/stdlib2.html#decimal-floating-point-arithmetic) ::: ## 課題① ### 次のファイル「script.py」を作成し、コマンドライン上で「python3 script.py one two three four five」を実行したときの結果として正しいものはA~Dのどれでしょうか? [ script.py ] ``` import sys print(sys.argv[0:4]) ``` **A**  ['script.py', 'one', 'two', 'three'] **B**  ['script.py', 'one', 'two', 'three', 'four'] **C**  ['python3', 'script.py', 'one', 'two'] **D**  ['python3', 'script.py', 'one', 'two', 'three'] *** ## 課題② ### モジュールに関する次の記述のうち誤っているものはどれか。 **A**  mathモジュールを使うと、コード処理の実行時間を計測できる。 **B**  smtplibモジュールを使うと、任意のインターネット上のホストにメールを送ることができる。 **C**  randomモジュールを使うと、疑似乱数を生成することができる。 **D**  statisticsモジュールを使うと、数値データの基本統計量(平均、中央値、分散など)を取得することができる。 *** ## 課題③ ### 「fibo.py」を作成し、コマンドラインで「コード」を実行したときの結果として正しいものはA~Dのどれでしょうか? [fibo.py] ``` def fib(n): a, b = 0, 1 while a < n: print(a, end=' ') a, b = b, a+b print() def fib2(n): a, b = 0, 1 while a < n: print(a, sep=',') a, b = b, a+b print() ``` [コード] ``` import fibo fibo.fib(100) ``` **A**  0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 **B**  [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] **C**  0 1 1 2 3 5 8 13 21 34 55 89 **D**  0,1,1,2,3,5,8,13,21,34,55,89 *** ## 課題④ ### 以下のコードの実行結果として正しいものはA~Dのどれでしょうか? ``` import math print('{1:.3f}, {0:.5f}'.format(math.pi, math.e)) ``` **A**  1:3.141f, 0:2.71828f **B**  3.141, 2.71828 **C**  2.718, 3.14159 **D**  2.71828 3.141 ※今回のチュートリアルに記載がないため以下を参考にして下さい ヒント:[math](https://docs.python.org/ja/3/library/math.html#math.pi) ***