---
# System prepended metadata

title: '*2022/04/22 網路爬蟲 HW02*'
tags: [網路爬蟲]

---

###### tags: `網路爬蟲`
# *2022/04/22 網路爬蟲 HW02*
## 題目：
![](https://i.imgur.com/uROicYe.png)
## 程式碼：
```
num=int(input("Please enter an odd number: "))
num=int(num/2)+1#Only control the half of row

#The upper of half of diamond
for r in range(1, num):#Every Row
	for x in range(num - r):#Control the blank
	    print(' ',end = '')
	for y in range(2*r-1):#Control the start
	    if (y ==0) or (y==r*2-2):
	        print('*',end = '')
	    else:
	        print(' ',end = '')
	print("")

#The lower of half of diamond
for r in range(num):
	for x in range(r):
	    print(' ',end = '')
	for y in range(2*(num-r)-1):
	    if (y ==0) or (y==2*(num-r)-2):
	        print('*',end = '')
	    else:
	        print(' ',end = '')
	print("")


```
## 輸出結果：
![](https://i.imgur.com/YVEHR0P.png)

## 題目：
![](https://i.imgur.com/Qg3aama.png)
## 程式碼：
```
import random
ans=int(random.randint(1,100))
i=int(4)
Count=int(input("Please enter a number from 1 to 100: "))

while(Count!=ans and i>0):
    if (Count>ans):
        print("Too large! Try again! You still have ",i," times")
    else :
        print("Too small! Try again! You still have ",i," times")
    Count = int(input("Please enter a number from 1 to 100: "))
    i = i - 1

if (Count==ans):
    print("Congratulation! The correct number is %d", ans)
elif (Count>ans):
    print("Too Laage~~~~")
    print("You can't get this number!"+"The correct answer is ",ans)
else:
    print("Too Small~~~~")
    print("You can't get this number!" + "The correct answer is ", ans)

```
## 輸出結果：
![](https://i.imgur.com/0MGn8FM.png)

## 題目：
![](https://i.imgur.com/Y6IPSyI.png)
## 程式碼：
```
import random

def create():
    model = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49]
    list_1 = random.sample(model,7)

    print("大樂透開獎號碼:\n", end="")
    print("開出順序: ",end="")
    for i in range(0,6,1):
        print(list_1[i]," ",end="")
    print("特別號:",list_1[6])
    special=list_1[6]
    list_1.pop(6)
    list_1.sort()
    list_1.append(special)

    print("大小順序: ", end="")
    for i in range(0, 6, 1):
        print(list_1[i], " ", end="")
    print("特別號:", list_1[6])

    return list_1

list_Output=create()

```
## 輸出結果：
![](https://i.imgur.com/lV5o2QU.png)

## 題目：
![](https://i.imgur.com/fV8VOXf.png)
## 程式碼：
```
list_1=[0,0,0,0,0,0,0,0,0,0]
for i in range(0,10,1):
    list_1[i]=(i+1)**2
print(list_1)

def Filter_Function(num):
    return True if num>20 and num<80 else False
print(list(filter(Filter_Function,list_1)))

map(float,list_1)
list_2=[0,0,0,0,0,0,0,0,0,0]
for i in range(0,10,1):
    list_2[i]=list_1[i]/2.0
print(list_2)

tuple_example=2022,
print(type(tuple_example))

set_example=set()
print(type(set_example))

```
## 輸出結果：
![](https://i.imgur.com/nT3nX2H.png)



