---
# System prepended metadata

title: 11/2 Python基礎程式設計(二) 筆記
tags: [2023社課共筆]

---

# 11/2 Python基礎程式設計(二) Python Basic Tutorial (2)
> [name=陳昱逢][time=19:00][color=black]
:::warning
今天主要課程為Python中的==Operators== & ==Conditional Operation==

Today's main course covers ==Operators== and ==Conditional Operations== in Python. 
:::

## :beginner: Operators
:::success
Python的運算子分為算術、比較、邏輯、賦值、位元、成員和身份運算子。算術用於數學運算，比較用於值比較，邏輯用於邏輯操作，賦值用於變數賦值，位元用於二進位操作，成員用於檢查值是否在序列中，身份用於檢查對象標識。這些運算子在Python程序中起著關鍵作用，可應用於各種任務，包括數學計算和邏輯判斷。

In Python, operators are categorized into arithmetic, comparison, logical, assignment, bitwise, membership, and identity operators. Arithmetic operators are used for mathematical operations, comparison operators for value comparison, logical operators for logical operations, assignment operators for variable assignment, bitwise operators for binary operations, membership operators for checking values in sequences, and identity operators for verifying object identity. These operators play a crucial role in Python programs and are applicable to various tasks, including mathematical calculations and logical evaluations.
:::

![Python_programming.png](https://hackmd.io/_uploads/r1YxG1-m6.png)
:::info
- ** 是用來當作指數，3 ** 2 = 9
- // 是取除之後的整數部分 3//2 = 1
- %是用來取餘數 3 % 2 = 1
- ** is used for exponentiation. For example, 3 ** 2 = 9 means 3 raised to the power of 2 equals 9.
- // is used for floor division, which returns the integer part of the division result. For example, 3 // 2 = 1 means that the result of dividing 3 by 2 is 1 as an integer.
- % is used to find the remainder of a division. For example, 3 % 2 = 1 indicates that the remainder when 3 is divided by 2 is 1.
:::
![Python_programming (1).png](https://hackmd.io/_uploads/rypfM1WQT.png)
:::info
上一張簡報的延伸

The extension of last slide
:::
![Python_programming (2).png](https://hackmd.io/_uploads/SkS3zy-Xa.png)
:::info
- 字串利用加號連結就會加在一起 e.g. "hello"+" "+"hello" = hellohello
- ＊的話是將字串輸出x次 e.g. "a" * 3 = aaa

- When you use the plus + operator with strings, they are concatenated together. For example, "hello" + " " + "world" results in "hello world," where the strings are combined.
- Using the asterisk * operator with a string will replicate that string a specified number of times. For instance, "a" * 3 gives you "aaa" by repeating the string "a" three times.
:::
![Python_programming (3).png](https://hackmd.io/_uploads/Sye0fy-7a.png)
:::info
上節課提過，如果tuple中只有一個數字後面要加逗號，不然會被Python當成整數來用

In the previous lesson, it was mentioned that when you have a tuple with only one element, you should add a comma after the element. This is because without the comma, Python might interpret it as an integer rather than a tuple.
:::
:::success
e.g. 在寫code時常常需要讀寫檔案，如果我們在讀的時候，就可以利用+的符號，可以使用這些基本的運算子，會讓小專案更好打更方便融合，會讓小專案更好打更方便融合兩字串

e.g. 
Certainly, when writing code, working with file I/O, and using basic operators can make it more convenient and efficient to manipulate and merge two strings. These operations can be used for concatenating, splitting, and processing file contents, making the code cleaner and more understandable.

For example, you can use the '+' operator to concatenate strings, which is very useful for dynamically generating file content. You can also use the '*' operator to duplicate and repeat strings to create specific output formats.

Additionally, comparison operators can be used to check specific conditions within file content or strings, logical operators can combine multiple conditions, and conditional operators (such as the ternary conditional operator) can be used to perform conditional operations.
:::
### :pencil: 同學提問 Some Question from students
| **Number** | **Question** | **Given Answer** |
|:--------------:|:---------------:|:--------:|
|               沒有問題！No question!                      |

## :triangular_flag_on_post: Conditional Operation
:::success
比較運算元通常會回傳回傳布林值，以測試條件是否為真，例如 == 為等於，3 == 5會回傳false，因為3不等於5

Comparison operators typically return Boolean values to test whether a condition is true. For example, == tests for equality, and 3 == 5 will return False because 3 is not equal to 5.
:::
![Python_programming (4).png](https://hackmd.io/_uploads/r1gRfyb7a.png)
:::info
上面簡報列出必較運算元，如果是字元或是字串則是比較ASCII值(如果要測試ASCII值，可以打```print(ord("c"))```)出來會是99，也就是c的ASCII值，而```print(chr(99))```可以將ASCII值轉成字串輸出

In the presentation, the comparison operators were listed. When comparing characters or strings, ASCII values are compared. To test the ASCII value of a character, you can use the ord() function. For example, ```print(ord("c"))``` will output 99, which is the ASCII value for the character 'c'. Conversely, you can use the chr() function to convert an ASCII value to a string. For example, ```print(chr(99))``` will output the string "c" by converting the ASCII value 99 back to its corresponding character.
:::
:arrow_right:[ASCII Table Link](https://simple.m.wikipedia.org/wiki/File:ASCII-Table-wide.svg)

![Python_programming (5).png](https://hackmd.io/_uploads/SkxAGyWmp.png)

![Python_programming (6).png](https://hackmd.io/_uploads/BkeRf1bma.png)

![Python_programming (7).png](https://hackmd.io/_uploads/SJlRz1Wma.png)

![Python_programming (8).png](https://hackmd.io/_uploads/rJeCf1bma.png)
:::info
list & tuple的話會從左到右依序比較，不過不能比較1與"1"因為1是int然而"1"是字元


When comparing elements in a list or tuple, Python will compare them from left to right in sequence. However, you are correct that you cannot directly compare values of different types. For example, you cannot directly compare 1 (an integer) with "1" (a string) because they are of different data types.
:::
![Python_programming (9).png](https://hackmd.io/_uploads/SJeAG1bQ6.png)
![Python_programming (10).png](https://hackmd.io/_uploads/BylAG1ZmT.png)
![Python_programming (11).png](https://hackmd.io/_uploads/BJlRGybQT.png)
:::info
記住！0在電腦中為false，非0即為true
:::
![Python_programming (12).png](https://hackmd.io/_uploads/BkxRz1bXp.png)
:::info
如果list中有1，就會回傳true
:::
:::success
e.g. ```True```與```False```最常用的運算在於```if elif```中擔任判斷的依據，例如說，我今天只要從使用者那邊拿到 0 - 9的字元，在ASCII code中為48-57，所以我可以說只有 ```x >= 48 and x <= 57```時，我才拿進程式中，這樣一來，如果x是```'a'```也就是 97，條件運算元就會回傳```false```，程式就不會拿這個data

For example, ```True``` and ```False``` are most commonly used in ```if``` and ```elif``` statements to serve as conditions for decision-making. For instance, if I want to only accept character inputs from the user in the range of 0 to 9, which corresponds to ASCII values between 48 and 57, I can specify the condition ```x >= 48 and x <= 57```. This way, if x is ```'a'```, which corresponds to 97 in ASCII, the condition will evaluate to ```False```, and the program won't process this data. Please do not delete anything.
:::
### :pencil: 同學提問 Some Questions
| **Number** | **Question** | **Given Answer** |
|:--------------:|:---------------:|:--------:|
|            No question!         |

![Python_programming.png](https://hackmd.io/_uploads/S17SXf-mp.png)
:::info
```if```和 ```elif```讓我們可以依據不同情況來做下面的行為，比如```if(分數>90) print("A+")```如果分數超過90分，就會印出A+。
```elif```不可單獨使用，因爲是```else if```，代表說一定是原本的```if```條件不符合，才會來看這個```elif```有沒有符合，如果沒符合，就繼續往下看其他的```elif```或是```else```，```else```則是通常放在一串```if```或```elif```後面，代表說前面所有條件都不符合，才會執行這個程序。```if```或 ```elif```後面的()中會填上運算元，該運算元會回傳```true``` 或 ```false```，也就是前面所提到的運作方式！如果是```true```就會執行，```false```就不會執行，而是往下看```elif```或```else```

```if``` and ```elif``` statements allow us to perform different actions based on different conditions. For example, ```if (score > 90): print("A+")``` will print ```"A+"``` if the score is above 90.

```elif``` cannot be used alone; it stands for "else if," which means it is only considered when the original ```if``` condition is not met. If it doesn't match, the program proceeds to check other ```elif``` conditions or the else block. ```else``` is typically placed after a series of ```if``` or ```elif``` statements, indicating that none of the preceding conditions were met.

The ```if``` and ```elif``` statements are followed by parentheses, where an expression is evaluated, returning ```True``` or ```False``` based on the previously mentioned operation. If the expression is ```True```, the associated block of code is executed, and if it's ```False```, the program moves on to check the ```elif``` or ```else``` conditions. Please do not delete any characters.
:::

![Python_programming (1).png](https://hackmd.io/_uploads/rJ9I7MWXa.png)

![Python_programming (2).png](https://hackmd.io/_uploads/rkucXM-Q6.png)

![Python_programming (3).png](https://hackmd.io/_uploads/rJRyEGb7a.png)


![Python_programming (4).png](https://hackmd.io/_uploads/BkeZVGb7T.png)

![Python_programming (5).png](https://hackmd.io/_uploads/SJ2WEM-m6.png)





## :desktop_computer: Google Cloud Study Jam: GenAI Edition 2023
- Date: 12/09/2023 
- Time: 9:00 - 17:00
:::success
GDSC將在 2023/12/09 舉辦Google Cloud + 生成式AI工作坊，此活動會帶著大家利用Google Cloud的平台學習生成式AI的運作方式及原理，並有機會獲得限定獎勵！

GDSC will host a Google Cloud + Generative AI Workshop on December 9, 2023. This event will guide participants in using the Google Cloud platform to learn about the operation and principles of generative AI. There's also an opportunity to receive exclusive rewards.
:::

### :small_blue_diamond: What is Google Cloud:
Google Cloud 是 Google 將自己的雲端平台基礎建設（如：虛擬機器、網路、儲存空間、資料分析或機器學習服務等等）開放給程式開發者、IT 人員佈建自己的系統或程式

Google Cloud is Google's cloud platform infrastructure, which includes services such as virtual machines, networking, storage, data analytics, and machine learning, made available for developers and IT professionals to build their own systems and applications.


### :small_blue_diamond: Why to learn Google Cloud:
學會 Google Cloud，您可以做到以下幾件事（包含但不限於），例如：
1. 部署自己的網站，供全世界的用戶存取。
2. 隨時在 Google Cloud 上建立或刪除虛擬機器，提供各種測試或開發用途。
3. 使用 Google Cloud 上的 AI 或 ML 服務，開發自己的智慧應用程式。 
4. 使用 Google Cloud 上的資料分析工具，完成大數據的資料處理及分析。

By mastering Google Cloud, you can achieve several capabilities, including but not limited to:

1. Deploying your own website, making it accessible to users worldwide.
2. Creating or deleting virtual machines on Google Cloud at any time, for various testing or development purposes.
3. Developing intelligent applications using AI or ML services on Google Cloud.
4. Performing data processing and analysis of large datasets using data analytics tools available on Google Cloud.
### :small_blue_diamond: Why to join Cloud Study Jam:
:::success
1. 提供一個月免費存取 Google Cloud Skills Boost 
參加 Cloud Study Jam 的人都能獲得 1 個月免費存取 Google Cloud Skills Boost 平台的權利（吃到飽，價值約美金 30 元）
2. 動手操作 Labs
運用真實的 Google Cloud 環境來學習如何操作及使用 Google Cloud 的功能，活動中有人帶領一步步完成，彼此也能互相幫助排除困難。
:::

:::success
1. Offer a One-Month Free Access to Google Cloud Skills Boost
Participants in the Cloud Study Jam will receive a one-month free access to the Google Cloud Skills Boost platform, which includes unlimited access, valued at approximately $30 USD.
2. Hands-On Labs
Engage in hands-on experience with real Google Cloud environments to learn how to operate and utilize Google Cloud features. During the event, there will be guides to lead you through the process step by step, and participants can also assist each other in troubleshooting challenges.
:::




### :small_blue_diamond: Expected Challenges:

- *Gen AI Arcade Game* (8 labs)

- *Google Cloud Computing Foundation* (40 labs)

##  回饋表單！Feedback Form!
:::info
[表單連結](https://forms.gle/rLFU1wedV5TzshZcA)  :arrow_left: 
請幫我們填寫表單！讓我們的程式教學更加進步～
:::

## :timer_clock: 之後社課時間 Timeline

:::success
再過兩週就將結束Python基礎程式設計，即將利用所學知識來製作實用的工具了！

In just two weeks, you will complete the Python fundamentals course and be ready to apply your newfound knowledge to create practical tools and applications!
:::

|        **Course**        | **Date** | **Note** |
|:----------------------:|:--------:|:--------:|
| Python基礎程式設計(三)   |     11/9     |     EC5012     |
| Python基礎程式設計(四)   |      11/16    |     EC5012     |
| 基礎網路爬蟲             |      11/23    |     EC5012     |
|Pygame遊戲實作(一)       |      11/30    |     EC5012     |
|Pygame遊戲實作(二)       |      12/7    |     EC5012     |＝

|        **Course**        | **Date** | **Note** |
|:----------------------:|:--------:|:--------:|
| Python Basic Tutorial (3)   |     11/9     |     EC5012     |
| Python Basic Tutorial (4)   |      11/16    |     EC5012     |
| Basic Web scraping            |      11/23    |     EC5012     |
|Pygame game development      |      11/30    |     EC5012     |
|Pygame game development   |      12/7    |     EC5012     |＝