Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
第11回Network講座2019
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
北海道科学大学 電子計算機研究部
November 19, 2019
Education
86
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
第11回Network講座2019
北海道科学大学 電子計算機研究部
November 19, 2019
More Decks by 北海道科学大学 電子計算機研究部
See All by 北海道科学大学 電子計算機研究部
第12回Network講座2019
densan
1
69
第10回Network講座2019
densan
0
63
第09回Network講座2019
densan
1
180
第08回Network講座2019
densan
0
59
第07回Network講座2019
densan
0
61
第06回Network講座2019
densan
0
83
第05回Network講座2019
densan
0
60
第04回Network講座2019
densan
0
130
第03回Network講座2019
densan
0
48
Other Decks in Education
See All in Education
FA26 CLU MS Clinical Psychology New Student Orientation
jdbedics
0
170
ちいかわを読め
uchi8977
1
370
Sekolah Sabat - Triwulan 3 2026 - Pelajaran 12
hiola
0
12k
AI-Based Speaking Assessment of a Short-Term Study Abroad Program
uranoken
0
510
マークシート試験のTeX言語を用いた自動採点について
doratex
0
4.2k
Quality Control of Crude Drugs
pawan_pharm
0
160
Introduction - Lecture 1 - Web Technologies (1019888BNR)
signer
PRO
0
6.5k
AI時代のセキュリティ監査
matshogo
PRO
0
120
人間のために、人間と共に働く時代の終わりの始まり
frievea
0
200
Throw Yourself In! - How I've learned English and What I'm Facing
georgeorge
1
260
実践プレゼンテーション・デザイン
dragon2
1
130
CLASSIFICATION OF CRUDE DRUGS
pawan_pharm
0
190
Featured
See All Featured
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
42k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
340
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
340
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
200
Building the Perfect Custom Keyboard
takai
2
880
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
530
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
730
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
470
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.6k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Transcript
ネットワークチーム 第11回 2019 北海道科学大学 電子計算機研究部
INDEX ⚫ Python - セットアップ - 簡単な説明 ⚫ 演習 2
Python
Python について ⚫ 一番人気のプログラミング言語 ⚫ Javascript と同様のスクリプト言語 ⚫ 読みやすい&書きやすい ⚫
ブロックは { } ではなくインデント ⚫ サーバーサイドのプログラムに使用 4
セットアップ (1/2) https://www.python.org/downloads/windows/ から “Download Windows x86-64 executable installer” を
クリックしてダウンロード 5
セットアップ (2/2) インストールして “Python 3.8 (64bit)” を実行 6 入力してみよう print(“Hello”)
開発環境 本講座はコマンドラインを使用するが 開発環境は PyCharm を推奨 7 https://www.jetbrains.com/pycharm/
変数について variable
変数のイメージ(再掲) 変数とは値を入れておくための箱 9 変数名は自由につけることができる num 変数→
変数の宣言 Pythonにおいて、変数の宣言は必要ない 変数の型は、代入した値に応じて自動的に決まる 10 num = 10 ←数値 str =
“densan” ←文字列 num = 3 構文 num
変数の演算(再掲) + や – を、プログラミングでは演算子という。 変数と演算子を使うことで計算ができる。 11 num bar =
num + foo bar foo + 代入
変数 まとめ 変数とは ⚫ プログラム上で、処理に使う数値などのデータ(値)に 名前をつけて保持するためのもの。 ⚫ Pythonにおいて、変数のみの宣言は必要ない。 ⚫ 変数に値を入れる事を、値を代入するという。
構文 12 変数の作成 変数名 = 値 値の代入 変数名 = 値
配列について Array, List
配列とは(再掲) 配列とは、複数の変数を一つに纏めたものである。 Pythonでは配列に相当するリストが使用可能 14 リストと配列は仕組みが違うが 使用感はだいたい同じ
リスト 配列と同様に、変数名と添え字を使って管理する。 宣言の方法は以下の通り。 15 リスト名 = [値1, 値2, 値3] list
= [2, 17, 3] 構文 list[0] list[1] list[2]
リスト 要素の追加 (1/2) 末尾に要素を追加する場合 append を使用する 16 リスト名.append(値) list.append(10) 構文
list[0] list[1] list[2] list[3] 10
リスト 要素の追加 (2/2) 要素を挿入する場合 insert を使用する 17 リスト名.insert(番号,値) list.append(2, 10)
構文 list[0] list[1] list[2] 10 list[3]
リスト 要素の削除 要素を削除する場合 del を使用する 18 del リスト名[番号] del list[2]
構文 list[0] list[1] list[2]
リスト まとめ リストとは ⚫ 複数の変数を「一つの変数名と添え字」で管理するもの。 ⚫ 添字は0から始まる。 - 10個の値を格納した場合、最後の要素の添字は9 ⚫
値を呼び出す場合は 変数名[添え字] と記述する。 構文 19 リストの作成 リスト名 = [値1, 値2, 値3] 値の代入 リスト名[添字] = 値 値の追加 リスト名.append(値) 値の挿入 リスト名.insert(番号,値) 値の削除 del リスト名[番号]
関数について function
関数のイメージ(再掲) 関数とは工場のようなもの 21 2乗する関数 9 関数に3を渡すと9が返ってくる。
関数のイメージ(再掲) このとき、関数に渡す値を引数という。 また、結果の値を返り値又は戻り値という。 22 2乗する関数 9 引数 戻り値
関数のイメージ(再掲) 関数によっては ⚫ 引数がない ⚫ 戻り値がない ⚫ どちらもない 場合もある 23
HI! と表示 する関数 文字を表示するだけなので 引数も戻り値も必要ない。
関数の定義 関数は自分で定義することができる。 24 def 関数名(引数) : 処理… return 返り値 def
square(num) : squ = num *num; return squ 構文
関数の呼び出し 関数を実行することを、関数を呼び出すという。 25 関数名(引数) a = square(3) 構文 aに9が代入される
関数まとめ 関数とは ⚫ 処理をひとまとめにした命令群。 ⚫ 関数を実行する事を、関数を呼び出すという。 ⚫ 関数を呼び出す際に、値を渡すことができる。 この値を引数(ひきすう)という。 ⚫
関数は呼び出し元へ実行結果の値を返すことができる。 この値を返り値又は戻り値という。 構文 26 関数の宣言 def 関数名(引数) : 処理… return 返り値
ラムダ式 ラムダ式(lambda)とは名前のない関数のこと 27 lambda 引数: 処理… def square(num) : squ
= num *num; return squ 構文 square = lambda a: a * a 同じ処理
分岐
if 文 if 文は処理を分岐するときに使用する。 条件が真ならば、ブロック内の処理が行われる。 29 if 条件 : 処理…
elif 条件 : 処理… else : 処理… 構文 条件が偽であれば 下の elif が判定される。 いずれにも当てはまらない場合 else の処理が実行される。
三項演算子 if 文は一行で書くことができる。 これを三項演算子という。 30 構文 真の処理… if 条件 else
偽の処理… num = -3 if num > 0: ab = num else: ab = -num num = -3 ab = num if num > 0 else -num 同じ処理
繰り返し
for文 (1/3) for文は繰り返す回数が決まっているときに使用する。 range() を使うことで、簡単に記述する事ができる。 32 for 変数 in range(回数)
: 処理… 構文 for 変数 in range(開始, 終了) : 処理…
for文 (2/3) 前述のリストなどをループで回す時は 対象のオブジェクトを条件式に用いれば良い 33 for 変数 in オブジェクト: 処理…
構文
for文 (3/3) enumerate() を使うことで 添字と中身を一緒に取り出すことができる 34 for 変数1, 変数2 in
enumerate(回数) : 処理… 構文 l = ["Gouda", "Kanda", "Akasaka"] for i, name in enumerate(l): print(i, name) 0 Gouda 1 Kanda 2 Akasaka
while文 while文は繰り返す回数が決まっていないきに使用する。 35 while 条件式: 処理… 構文 while True: print(“呪”,
end=“”) ↑無限ループ
ライブラリ
ライブラリのインポート ライブラリを使用するには import を使用する また、as で別名を付けることができる 37 import ライブラリ名 import
ライブラリ名 as 別名 構文 import numpy as np
numpy numpy とは多次元配列の計算を行うライブラリ 38 import numpy as np A =
np.array([[3, 1, 5], [1, 1, 1], [0, 1, 2]]) print(np.linalg.det(A)) print(np.linalg.inv(A)) 死ぬほど面倒な行列式や逆行列の計算が 一瞬で終わる
演習 10-1
演習 10-1 サーボモータを図のように接続 40
演習 10-1 赤ワイヤ 41 黒ワイヤ 黄ワイヤ
演習 10-1 ~/nwt に servo.py を作成して 次のプログラムを作成 42 import re
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) gp_out = 4 GPIO.setup(gp_out, GPIO.OUT) servo = GPIO.PWM(gp_out, 50) servo.start(0) time.sleep(0.2) servo.ChangeDutyCycle(7.5) time.sleep(2) servo.ChangeDutyCycle(2.5) time.sleep(2) servo.stop() GPIO.cleanup() pi@raspberrypi:~ $ mkdir nwt pi@raspberrypi:~ $ cd nwt pi@raspberrypi:~/nwt $ vi servo.py ターミナルのコマンド servo.py 1. 2.
演習 10-1 43 pi@raspberrypi:~/nwt $ sudo python servo.py ターミナルのコマンド 3.:wq
で保存 4.servo.py を実行!
本日の講座はここまで お疲れ様でした