Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b1ffcaa

Browse files
solved 30
1 parent 46c848e commit b1ffcaa

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

30.py

+64-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import download_file
22
import csv
3+
from PIL import Image
4+
from PIL import ImageDraw
35

46

57
def main():
68
url = "http://www.pythonchallenge.com/pc/ring/yankeedoodle.csv"
79
file_path = "relax/yankeedoodle.csv"
10+
pic_path = "relax/hint.png"
811
user = "repeat"
912
password = "switch"
1013
# first_step(url, file_path, user, password)
11-
second_step(file_path)
14+
floats = second_step(file_path)
15+
points = third_step(floats)
16+
fourth_step(points, pic_path)
17+
an = fifth_step(floats)
18+
sixth_step(an)
1219

1320

1421
def first_step(url, file_path, user, password):
@@ -18,8 +25,63 @@ def first_step(url, file_path, user, password):
1825
def second_step(file_path):
1926
with open(file_path, newline="") as csvfile:
2027
spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
28+
floats = []
2129
for row in spamreader:
22-
print(" ".join(row))
30+
for i in range(len(row)):
31+
floatStr = row[i][0:-1]
32+
floats.append(float(floatStr))
33+
return floats
34+
35+
36+
def third_step(input):
37+
points = []
38+
for i in range(len(input)):
39+
point = input[i] * 0x100
40+
points.append(int(point))
41+
return points
42+
43+
44+
def fourth_step(input, path):
45+
width = 139
46+
height = 53
47+
im = Image.new("P", (width, height))
48+
drawer = ImageDraw.Draw(im)
49+
counter = 0
50+
for x in range(width):
51+
for y in range(height):
52+
drawer.point((x, y), input[counter])
53+
counter += 1
54+
im.save(path)
55+
56+
57+
def fifth_step(input):
58+
an = []
59+
x = "0"
60+
y = "0"
61+
z = "0"
62+
for i in range(len(input)):
63+
if i % 3 == 0:
64+
if len(str(input[i])) > 5:
65+
x = str(input[i])[5]
66+
elif i % 3 == 1:
67+
if len(str(input[i])) > 5:
68+
y = str(input[i])[5]
69+
elif i % 3 == 2:
70+
if len(str(input[i])) > 6:
71+
z = str(input[i])[6]
72+
an.append(int(x + y + z))
73+
x = "0"
74+
y = "0"
75+
z = "0"
76+
return an
77+
78+
79+
def sixth_step(input):
80+
result = ""
81+
for i in range(len(input)):
82+
value = chr(input[i])
83+
result += value
84+
print(result)
2385

2486

2587
if __name__ == "__main__":

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# pythonchallenge
22
Solve Problems in http://www.pythonchallenge.com
33

4+
#### 30
5+
result: http://www.pythonchallenge.com/pc/ring/grandpa.html
6+
```python
7+
import csv
8+
```
9+
- csv lib for handle csv tables, csv for Comma-Separated Values
10+
- 7367 factored result: 53 and 139
11+
412
#### 29
513
result: http://www.pythonchallenge.com/pc/ring/yankeedoodle.html
614
- do you find these unnecessary empty lines in the source page of guido.html

relax/hint.png

7.59 KB
Loading

relax/yankeedoodle.jpg

40.1 KB
Loading

0 commit comments

Comments
 (0)