# Python筆記
## ==所有條件式後面必需加冒號==
Pyphon編譯=>python3
## 運算子
### /
除法
### //
除後取商數的整數部分
### %
除後取餘數
### **
平方
## if判斷結構
EX:
```python
if (n%3 ==0):
print("good")
elif (n%3==1):
print("soso")
elif (n%3==2):
print("bad")
```
if條件要以==冒號==做結尾
程式區塊需要以==TAB做==縮排
## for重複結構
==break為跳出迴圈==

### for+range凾式

起始值預設為==0==,遞增值預設為==1==
EX:
```python=
for i in range (0,5,1):
print(i)
```
執行結果為
0
1
2
3
4
==不會有5!!!==
### for+字串

EX:
```python=
string = "Python"
for i in string:
print(i)
```
執行結果為
P
y
t
h
o
n
## while重複結構

==Python的while是滿足條件會執行迴圈,並不是滿足條件停止迴圈==
EX:
```python=
x=5
while(x>1):
print(x)
x-=1
```
執行結果為
5
4
3
2
## 列表建構
假設有一串數字為 20 40 30 40 可用列表建構把字串拆成列表
num = [int(x) for x in input().split()]
---------輸出----將字串利用split拆開並給x---------------------------------------
-----(x從後面取得)-----------------------------------------------------------------

EX:
```python=
num = [int(x) for x in input().split()]
print(num)
```
執行結果為
[1, 2, 3, 4]
## 若給多個變數則會分配給所有變數
EX:
```python=
a, b, c = [int(x) for x in input().split()]
print(a)
print(b)
print(c)
```
執行結果為
1
2
3
## 實作
### 1.3rd
```python=
from pwn import *
c = remote("140.110.112.213", 2403)
print(c.recvlines(3))
for x in range(100):
print(c.recvlines(2))
c.sendline(str(x+1))
print(c.recvline())
c.close()
```
### 2.count
```python=
from pwn import *
c = remote("140.110.112.213", 2400)
c.recvlines(6)
c.recvuntil(b"numbers : ")
l = c.recvline()
a = [int(x) for x in l.split()]
a.sort(reverse = True)
c.sendlineafter(b"answer : ",str(a[2]).encode())
print(c.recvline())
c.close()
```
### 3.clendar(未完成)
```python=
from pwn import *
c = remote("140.110.112.213", 2402)
for x in range(100):
c.recvuntil(b"year : ")
a = c.recvline()
if ((int(a)%400==0) or (int(a)%4==0 and int(a)%100!=0)):
c.sendlineafter(b"answer : ","leap".encode())
else:
c.sendlineafter(b"answer : ","ordinary".encode())
print(c.recvline())
c.close()
```