This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
long_list = [ | |
703, 513, 444, 201, 562, 992, 214, 895, 847, 651, | |
134, 978, 238, 119, 820, 449, 94, 51, 374, 670, | |
923, 158, 614, 771, 877, 82, 346, 687, 304, 530, | |
"apple", "banana", "cherry", "date", "elderberry", | |
"fig", "grape", "honeydew", "kiwi", "lemon", | |
"mango", "nectarine", "orange", "papaya", "quince", | |
"raspberry", "strawberry", "tangerine", "ugli fruit", "watermelon", | |
1831, 4827, 9021, 5209, 6554, | |
"dog", "cat", "bird", "fish", "hamster", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 定義一個計算成績等第的 function | |
def show_grade(student_name, student_score): | |
# 完成 show_grade 函數 | |
# 使用 function 處理每位學生 | |
students = [ | |
{"name": "Alice", "score": 85}, | |
{"name": "Bob", "score": 72}, | |
{"name": "Charlie", "score": 67}, | |
{"name": "Diana", "score": 93} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 學生成績 | |
student1_name = "Alice" | |
student1_score = 85 | |
if student1_score >= 90: | |
student1_grade = "A" | |
elif student1_score >= 80: | |
student1_grade = "B" | |
elif student1_score >= 70: | |
student1_grade = "C" | |
elif student1_score >= 60: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from glob import glob | |
import re | |
import urllib.request | |
paths = glob('Notes/*.md') | |
results = [] | |
for path in paths: | |
with open(path, 'r', encoding='UTF-8') as fin: | |
data = fin.read() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 比較可以重複利用牛頓法的寫法(使用 function pointer) | |
#include <iostream> | |
using namespace std; | |
typedef double (*Equation)(double x); // 把 function pointer 命名為 Equation | |
double diff(Equation f, double x, double h=1e-6) { | |
return (f(x + h) - f(x)) / h; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _LIST_H | |
#define _LIST_H | |
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) | |
#define container_of(ptr, type, member) ({ \ | |
const typeof( ((type *)0)->member ) *__mptr = (ptr); \ | |
(type *)( (char *)__mptr - offsetof(type,member) );}) | |
struct list_head { | |
struct list_head *next, *prev; |