搜尋此網誌

2026年7月3日星期五

For loop

animalLookup = {

    'a': ['aardvark', 'antelope'],

    'b': ['bear'],

    'c': ['cat'],

    'd': ['dog'],

}


for letter, animals in animalLookup.items():

    if len(animals) > 1:

        continue

    print(f'Only one animal! {animals[0]}')


for letter, animals in animalLookup.items():

  • .items() gives you key-value pairs from the dictionary.

  • letter will be the key ('a', 'b', etc.).

  • animals will be the list of animals associated with that key.

Example iteration:

  • First loop: letter = 'a', animals = ['aardvark', 'antelope']

  • Second loop: letter = 'b', animals = ['bear']

  • …and so on.


if len(animals) > 1: continue

len(animals) counts how many animals are in the list.
If there are more than one, the loop skips this iteration (continue means “go to the next loop cycle”).
So 'a' (two animals) will be skipped.

print(f'Only one animal! {animals[0]}')

This runs only if the list has exactly one animal.
animals[0] gets the first (and only) item in the list.
It prints a message like:
"Only one animal! bear"

The f before the string tells Python: evaluate expressions inside {}.
{animals[0]} is replaced with the first element of the list.
For 'b', animals[0] = 'bear'.
So the actual string becomes:
"Only one animal! bear"

The curly brackets {} in are part of the f‑string syntax. They tell Python: “evaluate whatever is inside these brackets and insert the result into the string.”

A prime number is a natural number greater than 1 that has no divisors other than 1 and itself.

  • Example: 2,3,5,7,11,13...

  • Non‑prime (composite) numbers can be divided evenly by other numbers (e.g. 6=2×3).


In Python, the symbol ** is the exponentiation operator. It raises a number to the power of another number.

for number in range(2, 100):
    for factor in range(2, int(number ** 0.5) + 1):
        if number % factor == 0:
            break
    else:
        print(f'{number} is prime!')


for number in range(2, 100):
  • Starts at 2 (the first prime).
  • Goes up to 99.

for factor in range(2, int(number ** 0.5) + 1):

Tries dividing number by all integers from 2 up to the square root of number.
Why square root?
If a number has a factor larger than its square root, the matching smaller factor would already have been found.
Example: For 36, factors are 2 × 18, 3 × 12, 6 × 6. Once you check up to 6 (√36), you’ve covered all possibilities.

if number % factor == 0: break

% is the modulus operator (remainder).
If remainder is 0, number is divisible by factor → not prime.
break exits the inner loop immediately.

else: print(f'{number} is prime!')

This else belongs to the for loop, not the if.
It runs only if the loop did not break (meaning no factors were found).
So the number is prime, and it prints the message.

Example trace

  • number = 7

    • Factors checked: 2 → not divisible, 3 → not divisible.

    • Loop ends without break.

    • else runs → prints "7 is prime!".

  • number = 9

    • Factors checked: 2 → not divisible, 3 → divisible.

    • break triggers.

    • else skipped → nothing printed.


The int() function truncates (drops the decimal part), not rounds.

Microsoft Copilot

室內拍攝

室內拍照是否需要閃光燈?

光線不足時︰APS-C DSLR 的內置閃光燈可以補光,但光線通常比較硬,容易造成「死白臉」或強烈陰影。

替代方法:外置閃光燈打到天花板或牆壁,光線會柔和很多。

三腳架的限制︰如果拍攝人物,慢快門會導致人物移動模糊,這時候閃光燈仍然有幫助。

如何讓光線自然︰

調整閃光輸出:在相機設定裡降低閃光補償(Flash Compensation),避免過曝。

混合環境光:快門速度設在 1/60–1/125 秒,讓環境光進入,再由閃光燈補主體。

Microsoft Copilot and summarized

NG

如果是在學習拍照,NG 代表 No Good(不良、錯誤)。

面對壓力

culprit: a person or thing responsible for causing a problem

connotation: ​an idea suggested by a word in addition to its main meaning

detrimental: harmful

perpetuate: to make something such as a bad situation, a belief, etc. continue for a long time

chore: a task that you do regularly

cortisol: a glucocorticoid C21H30O5 produced by the adrenal cortex upon stimulation by ACTH that mediates various metabolic processes (such as gluconeogenesis), has anti-inflammatory and immunosuppressive properties, and whose levels in the blood may become elevated in response to physical or psychological stress

head-on: direct or directly

distinction (between A and B) a clear difference or contrast especially between people or things that are similar or related

hand in: to give something to a person in authority, especially a piece of work or something that is lost

impending: (usually of an unpleasant event) that is going to happen very soon

doom: death or destruction; any terrible event that you cannot avoid

Stress plays an adaptive and positive role in facilitating personal growth and success in challenging situations. When managed appropriately, acute stress contributes to heightened productivity and effective decision-making. Adaptive stress encourages individuals to develop coping mechanisms, problem-solving skills and a greater capacity to navigate future difficulties.

面對挑戰時,壓力並非全然有害。適度且可控的壓力能喚起警覺與動機,促使人採取行動、學習新技能,從而提升能力與自信。在短期內,壓力還能激發注意力與能量,使人在限時或高要求的情境下更專注,進一步提升學習效果與決策能力。關鍵在於妥善管理,例如設定明確目標與安排適當休息,以避免壓力演變為慢性負擔。當人經歷並成功應對壓力情境後,會逐步累積經驗,學會解決問題、尋求資源及調整心態,長遠而言有助提升整體抗壓能力。

Explained by Microsoft Copilot and organized by Perplexity.ai

Minor self-amendments

hypervigilant: extremely alert, careful, or cautious; overly aware of one's environment and the potential dangers it presents

exaggerated: made to seem larger, better, worse or more important than it really is or needs to be

lethargic: without any energy or enthusiasm for doing things

berate: to criticize or speak angrily to somebody because you do not approve of something they have done

rut: a boring way of life that does not change

apathetic: showing no interest or enthusiasm

deplete: to reduce something by a large amount so that there is not enough left; to be reduced by a large amount

bout: a short period of great activity; a short period during which there is a lot of a particular thing, usually something unpleasant

whammy: an unpleasant situation or event that causes problems for somebody/something

innocuous: ​not harmful or dangerous

"Hustle and bustle" refers to a state of great, busy, and noisy activity. It typically describes crowded, energetic environments like big cities, marketplaces, or busy offices. People often use the phrase when expressing a love for city life or a desire to escape to a quieter place.

garnish: to decorate a dish of food with a small amount of another food

hindsight: the understanding that you have of a situation only after it has happened and that means you would have done things in a different way

lousy: terrible

advocate: ​to support something publicly

platonic: (of a relationship) friendly but not involving sex

conspire: (of events) to seem to work together to make something bad happen

Nicole Vignola "Rewire"

hk.dictionary.search.yahoo.com

oxfordlearnersdictionaries.com

merriam-webster.com/medical

dictionary.cambridge.org

His father

confide: to tell somebody secrets and personal information that you do not want other people to know

prestigious: respected and admired as very important or of very high quality

thriving: continuing to be successful, strong, healthy, etc.

Disk BASIC usually refers to early versions of the BASIC programming language modified to support floppy disk drives and disk file management (like loading and saving code files), rather than relying on cassette tapes or ROM chips.

down to the wire: until the last moment that it is possible to do something

live off: to use someone or something to provide the money or food that you need to live

takeout: a restaurant that cooks and sells food that you take away and eat somewhere else

back then: at a particular time in the past that you are talking about

convey: to express a thought, feeling, or idea so that it is understood by other people

in lieu of (something): instead of

nuance: a very slight difference in meaning, sound, color or somebody’s feelings that is not usually very obvious

hole up: to hide in a place

Bill Gates "Source Code"

Online Dictionaries Used:

hk.dictionary.search.yahoo.com

www.oxfordlearnersdictionaries.com

dictionary.cambridge.org

Google AI overview

2026年6月24日星期三

While loops

innocuous: not intended or likely to offend or upset anyone

tame something to make an animal, bird, etc. not afraid of people and used to living with them

The datetime class in Python is part of the datetime module and is used to represent both date and time together, with optional time zone support. It allows you to create, manipulate, and format date-time objects with precision, making it essential for scheduling, logging, and time-based calculations.

In Python, the % symbol is the modulus operator. It returns the remainder when one number is divided by another.

In Python, pass is a placeholder statement that literally means “do nothing.”


from datetime import datetime

wait_until = (datetime.now().second + 2) % 60

  • datetime.now().second → gets the current second (0–59).

  • + 2 → adds 2 seconds to the current time.

  • % 60 → ensures the value wraps around correctly (e.g., if current second is 59, 59 + 2 = 61, and 61 % 60 = 1).

So wait_until is always two seconds ahead of the current second.

while datetime.now().second != wait_until: print('Still waiting!')

  • This loop keeps checking the current second.

  • As long as it’s not equal to wait_until, it prints "Still waiting!".

print(f'We are at {wait_until} seconds!')

    Once the current second matches wait_until, the loop ends.
    It prints a confirmation message showing the target second.

In Python, the f in print(f"...") is shorthand for an f‑string, also called a formatted string literal. It lets you embed variables or expressions directly inside a string using curly braces {}.

name = "Tsz"
age = 25
print(f"My name is {name} and I am {age} years old.")

Output:
My name is Tsz and I am 25 years old.

A literal in Python (and in programming generally) is a fixed value that you write directly into your code. It represents itself, not a variable or expression. Examples are integer, float, string, and boolean.

from datetime import datetime

wait_until = (datetime.now().second + 2) % 60

while True:
    if datetime.now().second == wait_until:
        print(f'We are at {wait_until} seconds!')
        break

wait_until is set to 2 seconds ahead of the current second (wrapped with % 60).

The while True: loop runs indefinitely.

while → starts a loop that repeats as long as its condition is True.
True → is a Boolean literal that always evaluates to true.
So while True: means “keep looping forever” because the condition never becomes false on its own.

Inside, you check if datetime.now().second == wait_until.

When the condition is true, it prints the message and break exits the loop.


from datetime import datetime

wait_until = (datetime.now().second + 2) % 60

while True:   # outer loop runs forever
    while datetime.now().second == wait_until:   # inner loop runs only when condition is true
        print(f'We are at {wait_until} seconds!')
        break

When the condition is true, it prints the message once and then break exits the inner loop.
But notice: break only stops the inner loop, not the outer while True: loop.
That means the outer loop will continue running forever, checking again and again.


from datetime import datetime wait_until = (datetime.now().second + 2) % 60 while datetime.now().second != wait_until: continue print('Still waiting!') print(f'We are at {wait_until} seconds!')

wait_until is set to 2 seconds ahead of the current second (wrapped with % 60).
The while loop runs until the current second equals wait_until.

Inside the loop you wrote:
continue print('Still waiting!')

continue immediately jumps back to the start of the loop, skipping everything after it.
That means the print('Still waiting!') line is never executed.


from datetime import datetime wait_until = (datetime.now().second + 2) % 60 while True: if datetime.now().second < wait_until: continue break print(f'We are at {wait_until} seconds!')

Target second
wait_until is set to 2 seconds ahead of the current second, wrapped with % 60.

Infinite loop (while True:)
The loop runs continuously until you explicitly break out.

Condition check
If the current second is less than wait_until, the loop executes continue.
continue skips the rest of the loop body and goes back to the top, so nothing else happens.

Break
As soon as the current second is not less than wait_until (i.e., equal or greater), the loop executes break.
This exits the loop completely.

Final print
After breaking, the program prints the message showing the target second.

Suppose the current second is 18.
wait_until = (18 + 2) % 60 = 20.
While the clock shows seconds less than 20 (18, 19), the loop keeps spinning.
As soon as the clock reaches 20 or higher, the loop breaks.

Microsoft Copilot

三分法

「三分法」(Rule of Thirds)又稱「井字構圖法」,是視覺藝術中最經典、最穩妥的基礎構圖原則。它能避免主體呆板,透過將畫面分為九宮格來引導視覺動線,創造平衡與空間感。

核心原理
  1. 劃分九宮格:將畫面的長與寬各畫兩條等距的直線,劃分出 9 個相等的格子和 4 條分割線。
  2. 視覺焦點(交叉點):將照片的主體或重要元素,放置在四條線的四個交叉點上。
常見應用方式
  • 人物攝影:將人物的眼睛或身體軀幹對齊在垂直的三分之一線上,並為視線方向保留適當的空間。
  • 風景攝影:將地平線對齊在上方或下方的水平線上。若想強調天空,地平線放在下方 1/3 處;若想強調地面或水面,地平線則放在上方 1/3 處。
  • 引導視線:利用線條或物體(如道路、河流、橋樑)從三分之一處延伸,引導觀眾進入畫面深處。
Google AI overview