pf-7. 関数呼び出し

>100 Views

January 29, 23

スライド概要

トピックス:Python, Google Colaboratory, 関数呼び出し

Python 入門(Google Colaboratory を使用)(全8回)
https://www.kkaneko.jp/pro/pf/index.html

金子邦彦研究室ホームページ
https://www.kkaneko.jp/index.html

profile-image

金子邦彦(かねこくにひこ) 福山大学・工学部・教授 ホームページ: https://www.kkaneko.jp/index.html 金子邦彦 YouTube チャンネル: https://youtube.com/user/kunihikokaneko

シェア

またはPlayer版

埋め込む »CMSなどでJSが使えない場合

関連スライド

各ページのテキスト
1.

pf-7. 関数呼び出し (Python 入門,Google Colaboratory を使用) (全8回) URL: https://www.kkaneko.jp/pro/pf/index.html 金子邦彦 1

2.

関数の中の式の評価のタイミング foo(100) の値は 30000 a 100 x 300 foo(100) の値は 300000 a 100 x 3000 関数の中の式「a * x」の評価では, 最新の a の値,最新の x の値が用いられる 2

3.

• 関数の中で関数を呼び出す def foo(a): return a * 1.08 def bar(x): return foo(x) * 100 p = 12 print(bar(p)) p = 20 print(bar(p)) foo の呼び出し bar の呼び出し 3

4.

演習 資料:5 ~ 9 【トピックス】 • 関数呼び出し 4

5.

① Google Colaboratory のWebページを開く https://colab.research.google.com 5

6.

② 「ファイル」で,「ノートブックを新規作成」を選ぶ ③ Google アカウントでのログインが求められたときはログ インする 6

7.

④ コードセルを新規作成し,Python プログラムを入れる def foo(a): すべて半角文字 return a * 1.08 def foo(a) の直後に「:」 p = 120 print(foo(p)) 字下げ. (ここでは,半角の空白を 2つ) p = 200 print(foo(p)) ⑤ 実行結果を確認 7

8.

• これでは動かない 正しくない字下げ 正しい字下げ ここでは,半角の空白を 2つ 8

9.

⑥ コードセルを新規作成し,Python プログラムを入れる def foo(a): return a * 1.08 def bar(x): return foo(x) * 100 すべて半角文字 def foo(a) と def bar(x) の直後に「:」 字下げ. (ここでは,半角の空白を 2つ) p = 12 print(bar(p)) p = 20 print(bar(p)) ⑦ 実行結果を確認 9

10.

Python 関連ページ • Python まとめページ https://www.kkaneko.jp/tools/man/python.html • Python プログラミングの基本 Python Tutor, VisuAlgo, Code Combat を使用 https://www.kkaneko.jp/pro/po/index.html • Python プログラム例 https://www.kkaneko.jp/pro/python/index.html • 人工知能の実行(Google Colaboratory を使用) https://www.kkaneko.jp/ai/ni/index.html • 人工知能の実行(Python を使用)(Windows 上) https://www.kkaneko.jp/ai/deepim/index.html 10