###### tags: `Python勉強会` # Python勉強会 第5回 課題 :::info **<第5回Web会議日程>** 2024年03月21日(木) 19:00から **<第5回の自習範囲>** **【Pythonチュートリアル】** https://docs.python.org/ja/3.9/tutorial/index.html [8. エラーと例外](https://docs.python.org/ja/3/tutorial/errors.html) [8.1. 構文エラー](https://docs.python.org/ja/3/tutorial/errors.html#syntax-errors) [8.2. 例外](https://docs.python.org/ja/3/tutorial/errors.html#exceptions) [8.3. 例外を処理する](https://docs.python.org/ja/3/tutorial/errors.html#handling-exceptions) [8.4. 例外を送出する](https://docs.python.org/ja/3/tutorial/errors.html#raising-exceptions) [8.5. 例外の連鎖](https://docs.python.org/ja/3/tutorial/errors.html#exception-chaining) [8.6. ユーザー定義例外](https://docs.python.org/ja/3/tutorial/errors.html#user-defined-exceptions) [8.7. クリーンアップ動作を定義する](https://docs.python.org/ja/3/tutorial/errors.html#defining-clean-up-actions) [8.8. 定義済みクリーンアップ処理](https://docs.python.org/ja/3/tutorial/errors.html#predefined-clean-up-actions) [9. クラス](https://docs.python.org/ja/3/tutorial/classes.html) [9.1. 名前とオブジェクトについて](https://docs.python.org/ja/3/tutorial/classes.html#a-word-about-names-and-objects) [9.2. Python のスコープと名前空間](https://docs.python.org/ja/3/tutorial/classes.html#python-scopes-and-namespaces) [9.2.1. スコープと名前空間の例](https://docs.python.org/ja/3/tutorial/classes.html#scopes-and-namespaces-example) [9.3. クラス初見](https://docs.python.org/ja/3/tutorial/classes.html#a-first-look-at-classes) [9.3.1. クラス定義の構文](https://docs.python.org/ja/3/tutorial/classes.html#class-definition-syntax) [9.3.2. クラスオブジェクト](https://docs.python.org/ja/3/tutorial/classes.html#class-objects) [9.3.3. インスタンスオブジェクト](https://docs.python.org/ja/3/tutorial/classes.html#instance-objects) [9.3.4. メソッドオブジェクト](https://docs.python.org/ja/3/tutorial/classes.html#method-objects) [9.3.5. クラスとインスタンス変数](https://docs.python.org/ja/3/tutorial/classes.html#class-and-instance-variables) [9.4. いろいろな注意点](https://docs.python.org/ja/3/tutorial/classes.html#random-remarks) [9.5. 継承](https://docs.python.org/ja/3/tutorial/classes.html#inheritance) [9.5.1. 多重継承](https://docs.python.org/ja/3/tutorial/classes.html#multiple-inheritance) [9.6. プライベート変数](https://docs.python.org/ja/3/tutorial/classes.html#private-variables) [9.7. 残りのはしばし](https://docs.python.org/ja/3/tutorial/classes.html#odds-and-ends) [9.8. イテレータ (iterator)](https://docs.python.org/ja/3/tutorial/classes.html#iterators) [9.9. ジェネレータ (generator)](https://docs.python.org/ja/3/tutorial/classes.html#generators) [9.10. ジェネレータ式](https://docs.python.org/ja/3/tutorial/classes.html#generator-expressions) [12. 仮想環境とパッケージ](https://docs.python.org/ja/3/tutorial/venv.html) [12.1. はじめに](https://docs.python.org/ja/3/tutorial/venv.html#introduction) [12.2. 仮想環境の作成](https://docs.python.org/ja/3/tutorial/venv.html#creating-virtual-environments) [12.3. pip を使ったパッケージ管理](https://docs.python.org/ja/3/tutorial/venv.html#managing-packages-with-pip) [14. 対話入力編集と履歴置換](https://docs.python.org/ja/3/tutorial/interactive.html) [14.1. タブ補完と履歴編集](https://docs.python.org/ja/3/tutorial/interactive.html#tab-completion-and-history-editing) [14.2. 対話的インタープリタの代替](https://docs.python.org/ja/3/tutorial/interactive.html#alternatives-to-the-interactive-interpreter) ::: ## 課題① ### 次のコードを実行して「整数a:」に「5」、「整数b:」に「0」を入力した場合の正しい結果はA~Dのどれでしょうか? ```javascript= try: int_a = int(input('整数a:')) int_b = int(input('整数b:')) print(int_a ** 2) print((int_a ** 2) / int_b) except(ValueError) as v: print(type(v)) print('C') except(ZeroDivisionError) : print('D') except: print('E') else: print('F') finally: print('G') ``` **A** 25 C F G **B** 25 0 C G **C** 25 D G **D** 25 D F G *** ## 課題② ### 仮想環境とパッケージに関する次の記述のうち誤っているものはA~Dのどれでしょうか? **A** pip install でパッケージ名を指定し、そのパッケージ名の後ろに==とバージョン名を付けると、そのバージョンのパッケージをインストールできる。 **B** pip install --upgradeとすることで、当該パッケージを最新バージョンにアップグレードすることができる。 **C** 「pip list パッケージ名」で、ある特定のパッケージの詳細情報が表示される。 **D** pip uninstall にパッケージ名を指定すると、その仮想環境からパッケージを削除できる。削除対象となるパッケージの複数指定も可能である。 **※参考内容**:[12.3. pip を使ったパッケージ管理](https://docs.python.org/ja/3/tutorial/venv.html#managing-packages-with-pip) *** ## 課題③ ### 「<span style="color:blue">sample.py</span>」を作成し、実行したときの結果として正しいものはA~Dのどれでしょうか? [<span style="color:blue">sample.py</span>] ```javascript= class Sample: c_list = [] def add_c_list(self,data): self.c_list.append(data) print("kekka:", end=" ") sample1 = Sample() sample1.add_c_list("shioya") sample2 = Sample() sample2.add_c_list("taketo") for item_data in sample1.c_list: print(item_data, end=" ") ``` **A** kekka: shioya taketo **B** kekka: **C** kekka: shioya **D** kekka: taketo shioya *** ## 課題④ ### 以下(1)~(4)のコードを実行すると、「<span style="color:red">構文エラー</span>」「<span style="color:red">例外</span>」どちらの結果になるでしょうか? (1) ```javascript= if i == "OFFICE54": print("OFFICE54") ``` (2) ```javascript= def divide(x): return 54 / x print(divide(0)) ``` (3) ```javascript= if x==1: print("1") ``` (4) ```javascript= d = {'a': 1, 'b': 2, 'c': 3} print(d['x']) ``` **A** ①構文エラー ②構文エラー ③例外 ④構文エラー **B** ①例外 ②構文エラー ③例外 ④例外 **C** ①構文エラー ②例外 ③例外 ④例外 **D** ①例外 ②例外 ③構文エラー ④構文エラー ヒント:[ZeroDivisionError](https://docs.python.org/ja/3/library/exceptions.html#ZeroDivisionError) [NameError](https://docs.python.org/ja/3/library/exceptions.html#NameError) [TypeError](https://docs.python.org/ja/3/library/exceptions.html#TypeError) ***
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up