Skip to content

Commit 4b00c10

Browse files
committed
Fix some bugs
1 parent 55113b3 commit 4b00c10

File tree

8 files changed

+22
-15
lines changed

8 files changed

+22
-15
lines changed

Bugs.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Python Challenge Solutions
22

33
This repository includes solutions to the Python Challenge quizzes for practice and fun.
4+
45
Website: [The Python Challenge](http://www.pythonchallenge.com/) — enjoy!
56

7+
(There are bugs in level_13、level_17 under python 3.13 on 2025.)
8+
69
### Level 0
710
2 to 38 = ?
811

@@ -104,4 +107,3 @@ Floats, image, formula.
104107
Google the grandpa rock and find the differences between two Mandelbrot images.
105108
See [Mandelbrot Set](https://en.wikipedia.org/wiki/Mandelbrot_set)
106109

107-
(There are bugs in level_07、level_13、level_15、level_17、level_30 under python 3.13.)

level_04.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def solve(url, NOTHING, MAXRANGE):
1919
nothing = NOTHING
2020
print("Following the nothing chain!")
2121
for i in range(int(MAXRANGE)):
22-
r = requests.get(url, params={'nothing': nothing})
23-
text = r.text
22+
response = requests.get(url, params={'nothing': nothing})
23+
text = response.text
2424
m = reo.search(text)
2525
print('{}: {}'.format(i, text))
2626
if m:

level_07.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ def solve(something):
3131
break
3232
box = (left, upper, right, lower)
3333
print("Selecting the message area: " + str(box))
34-
samplesize = ((right - left + 1) // 7, 1)
35-
text = im.crop(box).convert('L').resize(samplesize).tobytes().decode()
36-
hidden = "".join([chr(int(x)) for x in re.findall(r'\d+', text)])
37-
print("The hidden message is: {}\n".format(hidden))
38-
return hidden
34+
gray_im = im.crop(box).convert('L')
35+
text = ''.join(chr(gray_im.getpixel((x, 0))) for x in range(left, right, 7))
36+
print("The hidden message is: {}".format(text))
37+
# smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]
38+
result = "".join([chr(int(x)) for x in re.findall(r'\d+', text)])
39+
print("The result message is: {}\n".format(result))
40+
return result
3941

4042

4143
if __name__ == "__main__":

level_13.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111

1212
def solve(url):
13-
print("Looking up Bert(Evil):", end=' ')
13+
print("Looking up Bert(Evil):")
1414
phonebook = xmlrpc.client.ServerProxy(url)
1515
response = phonebook.phone('Bert')
1616
whom = re.findall(r'[A-Z]+', response)[0].lower()
17-
print(whom)
18-
print()
17+
println(whom)
18+
1919
return whom
2020

2121

level_15.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def solve(year):
2828
print('The given date: ' + year + '/01/27')
2929
# 1756/01/27
3030

31-
wikiurl = 'http://en.wikipedia.org/wiki/January_27'
31+
wikiurl = 'https://en.wikipedia.org/wiki/January_27'
3232
r = requests.get(wikiurl)
3333
text = catch(r.text, '<li><a href="/wiki/' + year + '.*?</a>(.*?)</li>')
3434
text = re.findall(r'<a.*?>(.+?)</a>', text)[0]

level_17.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def solve(url):
4848
# the flowers are on their way
4949
print()
5050
#
51-
print("Looking up Mozart's father (Leopold):", end=' ')
51+
print("Looking up Mozart's father (Leopold):")
5252
import xmlrpc.client
5353

5454
url2 = PREFIX_AUTH + '../phonebook.php'

level_30.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ def solve(something):
4949
# +str(x[i+2])[6]
5050

5151
result = []
52-
for a, b, c in perthree(text):
52+
for i in range(0, len(text), 3):
53+
group = text[i:i + 3]
54+
if len(group) != 3:
55+
break
56+
a, b, c = group
5357
result.append(int(a[5] + b[5] + c[6]))
5458
message = bytes(result).decode()
5559
return message

0 commit comments

Comments
 (0)