Stage 2: Work Session5
Stage 2: Work Session5
Practice With Lists
Exploring List Properties: You'll explore the difference between concatenating two lists with the + operator and appending with .append(). You'll also be introduced to a new operator +=.
實際操作:append 看來是直接加上這個element
append() 用在 list 添加元素
繼續測試,使用三種方法,一種是直接加,一種 .append,一種是+=
https://www.udacity.com/course/viewer#!/c-nd000/l-4170998786/e-4314441791/m-4302057440
學習使用隨機變數
先 import random
語法:using the random.randint(start, end) function
像 random.randint(0,10)
If we want to concatenate a string and a number, we need to convert the integer into a string using the str() function
e.g. print "Random number generated: " + str(random.randint(0,10))
想 input&output,演算邏輯,何時停止(stopping point)
思考表格內的空格
Product List練習:
Split
先把ml_string split 成一個個字串
設一個 for loop , go through each word in 剛轉成字串的 ml_string
找出 word 裡和 parts_of_speech 相同的值,assign 到 replacement 的變數
細節: ml_string 裡有一個值 ADJECTIVE! (內有驚嘆號)遇上parts_of_speech 中沒有驚嘆號的 ADJECTIVE,replacement 會顯示沒有驚嘆號的
如果對應上就顯示 None
Check 如果 replacement 不是 None,就把重複的字(replacement)換成corgi
relaced 這個空 list 加進 word (已經換好的字串堆)
把 replaced 字串堆 join 成一串
- 最後用 raw_input 方程式去換 corgi,創造 user_input
終端機的使用- Terminal
Terminal lets you interact with your computer at a lower level than is normally possible by typing commands into what is called a "shell."
Terminal is installed by default in a folder called "Utilities" within your "Applications" folder.
cd: Stands for "change directory."
ls: Stands for "list." The ls command lists all files and folders in the current directory.
IDLE- Python Shell
什麼是.pyc file
- A .pyc file is a Python file that has been translated into "byte code".
3.1 Introduction of abstraction
- 寫程式 Take a break
需求:二十分鐘就開 Youtube 聽歌休息一下