The document discusses various micro:bit accelerometer applications including:
- Reading acceleration values from the 3-axis accelerometer and controlling it.
- Examples like a electronic dice, movement indicator, tilt control game, and earthquake detector.
- Code snippets are provided for building applications like tracking dice rolls on shakes, showing direction arrows based on movement, and controlling a light sprite in a balancing game.
The document discusses functions in C language. It explains that functions can be divided into built-in functions and user-defined functions. Built-in functions are provided by the compiler as a "black box" that can be called, while user-defined functions are created by the user according to needs. User-defined functions have benefits like reusability, modularity and readability. It also talks about function prototypes, definitions, parameters, arguments, scope, and call by value and call by address.
The document discusses loops in programming. It covers for, while, and do/while loops as well as nested loops. It provides examples of calculating sums and finding narcissistic numbers using loops. Continues and breaks are also mentioned as ways to alter a loop's execution flow.
The document discusses various types of operators and expressions in C language, including: arithmetic operators, assignment operators, unary operators, binary operators, comparison operators, logical operators, and conditional statements like if and if/else. It provides examples of using these operators and statements to perform calculations and make comparisons. The key concepts covered are operators, expressions, arithmetic operations, assignment, increment/decrement, comparison, logical operations, and if/else conditional statements.
The document discusses variables and basic data types in C language. It covers topics such as variable and memory, basic data types, variable declaration and usage, truncation and overflow, address operator (&), constants and symbolic constants. The key points are:
1) A variable is a container that stores data in memory and its content may change as the program executes.
2) Basic data types include char, integer, float, etc. Each data type occupies a different size of memory and has a specific range of values.
3) Variables must be declared before use, specifying the data type and name. The variable name is a reference to the memory location where the data is stored.
10. 字串中的特殊字元使用逸出字元
使用'''起始與結束的內容會保留原來格式
content = "Hello Pythonn中文字測試nWelcome"
content2 = '''Hello Python
中文字測試
Welcome'''
常值(Literal) 6/6
10
脫逸字元 說明 脫逸字元 說明
' 單引號字元 " 雙引號
反斜線字元 n 換行
r 游標移至列首 t Tab鍵
v 垂直定位 a 響鈴
b 後退鍵 f 換頁
x 16進位字元碼 o 8進位字元碼
12. 保留字又稱關鍵字(Keyword),是Python語言具特定用途的識別字
Python3.x定義的保留字:
and as assert async await break
class continue def del elif else
except False finally for from global
if import in is lambda None
nonlocal not or pass raise True
return try while with yield
保留字
29. 算術運算子用來執行數學運算,包括加法、減法、乘法、除法、取餘
數等
算術運算子 1/2
運算子 說明 範例 執行結果(假設y值為3)
+ 將兩數字相加 x = y + 2 x變數值為5
- 將兩數字相減 x = y - 2 x變數值為1
* 將兩數字相乘 x = y * 2 x變數值為6
/ 浮點數除法運算 x = y / 2 x變數值為1.5
// 取除法之商數 x = y // 2 x變數值為1
% 取除法之餘數 x = y % 2 x變數值為1
** 指數 x = y ** 2 x變數值為9
35. Python語言在做邏輯運算時,會採取快捷運算(short circuit),來
加快執行速度
and運算時,如果第⼀個運算元為False,就直接回傳第⼀個運算元,
而不會再處理第二個運算元
or運算時,如果第⼀個運算元為True,就直接回傳第⼀個運算元,而
不會再處理第二個運算元
邏輯運算子 2/3
運算子 語法 執行結果 說明
and A and B 當A為False時回傳A;否則回傳B 只有A為True時,B才會被執行
or A or B 當A為True時回傳A;否則回傳B 只有A為False時,B才會被執行
not not A 當A為True時回傳False;否則回傳True
not之優先序比非邏輯運算低
not A==B執行順序為not(A==B)
44. x = 2 << 1 + 2
x = 2 << 3
x = 16
x = (2 << 1) + 2
x = 4 + 2
x = 6
x = 1 + 4 * 3 / 2 % 5
x = 1 + 12 / 2 % 5
x = 1 + 6 % 5
x = 1 + 1
x = 2
運算子的優先順序 3/4
45. x, y = 2, 3
x >= y and x != y or x * 2 > y
2 >= 3 and 2 != 3 or 4 > 3
False and 2 != 3 or 4 > 3
False and True or 4 > 3
False and True or True
Fasle or True
True
運算子的優先順序 4/4