Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb1ffcaa

Browse files
solved 30
1 parent46c848e commitb1ffcaa

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

‎30.py

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
importdownload_file
22
importcsv
3+
fromPILimportImage
4+
fromPILimportImageDraw
35

46

57
defmain():
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
deffirst_step(url,file_path,user,password):
@@ -18,8 +25,63 @@ def first_step(url, file_path, user, password):
1825
defsecond_step(file_path):
1926
withopen(file_path,newline="")ascsvfile:
2027
spamreader=csv.reader(csvfile,delimiter=' ',quotechar='|')
28+
floats= []
2129
forrowinspamreader:
22-
print(" ".join(row))
30+
foriinrange(len(row)):
31+
floatStr=row[i][0:-1]
32+
floats.append(float(floatStr))
33+
returnfloats
34+
35+
36+
defthird_step(input):
37+
points= []
38+
foriinrange(len(input)):
39+
point=input[i]*0x100
40+
points.append(int(point))
41+
returnpoints
42+
43+
44+
deffourth_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+
forxinrange(width):
51+
foryinrange(height):
52+
drawer.point((x,y),input[counter])
53+
counter+=1
54+
im.save(path)
55+
56+
57+
deffifth_step(input):
58+
an= []
59+
x="0"
60+
y="0"
61+
z="0"
62+
foriinrange(len(input)):
63+
ifi%3==0:
64+
iflen(str(input[i]))>5:
65+
x=str(input[i])[5]
66+
elifi%3==1:
67+
iflen(str(input[i]))>5:
68+
y=str(input[i])[5]
69+
elifi%3==2:
70+
iflen(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+
returnan
77+
78+
79+
defsixth_step(input):
80+
result=""
81+
foriinrange(len(input)):
82+
value=chr(input[i])
83+
result+=value
84+
print(result)
2385

2486

2587
if__name__=="__main__":

‎README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#pythonchallenge
22
Solve Problems inhttp://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)

[8]ページ先頭

©2009-2025 Movatter.jp