forked from jackfrued/Python-100-Days
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
45,740 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
nums = [] | ||
for i in range(100000): | ||
nums.append(i) | ||
nums.reverse() | ||
print(nums) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
nums = [] | ||
for i in range(100000): | ||
nums.insert(0, i) | ||
print(nums) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
a, b = 0, 1 | ||
for num in range(1, 101): | ||
a, b = b, a + b | ||
print(f'{num}: {a}') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from functools import lru_cache | ||
|
||
|
||
@lru_cache() | ||
def fib(num): | ||
if num in (1, 2): | ||
return 1 | ||
return fib(num - 1) + fib(num - 2) | ||
|
||
|
||
for num in range(1, 101): | ||
print(f'{num}: {fib(num)}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
""" | ||
公鸡5元一只,母鸡3元一只,小鸡1元三只,用100元买一百只鸡,问公鸡、母鸡、小鸡各有多少只? | ||
""" | ||
for x in range(21): | ||
for y in range(34): | ||
z = 100 - x - y | ||
if z % 3 == 0 and 5 * x + 3 * y + z // 3 == 100: | ||
print(x, y, z) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import re | ||
|
||
import PyPDF2 | ||
|
||
with open('Python_Tricks_encrypted.pdf', 'rb') as pdf_file_stream: | ||
reader = PyPDF2.PdfFileReader(pdf_file_stream) | ||
with open('dictionary.txt', 'r') as txt_file_stream: | ||
file_iter = iter(lambda: txt_file_stream.readline(), '') | ||
for word in file_iter: | ||
word = re.sub(r'\s', '', word) | ||
if reader.decrypt(word): | ||
print(word) | ||
break | ||
|
Binary file not shown.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import sys | ||
|
||
|
||
def fac(num): | ||
if num == 0: | ||
return 1 | ||
return num * fac(num - 1) | ||
|
||
|
||
def main(): | ||
print(fac(59996)) | ||
|
||
|
||
if __name__ == '__main__': | ||
sys.setrecursionlimit(60000) | ||
main() | ||
# for i in range(1000): | ||
# print(f'{i}:'.rjust(3), fac(i)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
def climb(num): | ||
a, b, c = 1, 2, 4 | ||
for _ in range(num - 1): | ||
a, b, c = b, c, a + b + c | ||
return a | ||
|
||
|
||
def main(): | ||
n = int(input('台阶数量: ')) | ||
print(climb(n)) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
""" | ||
迷宫寻路 | ||
""" | ||
import random | ||
import sys | ||
|
||
WALL = -1 | ||
ROAD = 0 | ||
|
||
ROWS = 10 | ||
COLS = 10 | ||
|
||
|
||
def find_way(maze, i=0, j=0, step=1): | ||
"""走迷宫""" | ||
if 0 <= i < ROWS and 0 <= j < COLS and maze[i][j] == 0: | ||
maze[i][j] = step | ||
if i == ROWS - 1 and j == COLS - 1: | ||
print('=' * 20) | ||
display(maze) | ||
sys.exit(0) | ||
find_way(maze, i + 1, j, step + 1) | ||
find_way(maze, i, j + 1, step + 1) | ||
find_way(maze, i - 1, j, step + 1) | ||
find_way(maze, i, j - 1, step + 1) | ||
maze[i][j] = ROAD | ||
|
||
|
||
def reset(maze): | ||
"""重置迷宫""" | ||
for i in range(ROWS): | ||
for j in range(COLS): | ||
num = random.randint(1, 10) | ||
maze[i][j] = WALL if num > 7 else ROAD | ||
maze[0][0] = maze[ROWS - 1][COLS - 1] = ROAD | ||
|
||
|
||
def display(maze): | ||
"""显示迷宫""" | ||
for row in maze: | ||
for col in row: | ||
if col == -1: | ||
print('■', end=' ') | ||
elif col == 0: | ||
print('□', end=' ') | ||
else: | ||
print(f'{col}'.ljust(2), end='') | ||
print() | ||
|
||
|
||
def main(): | ||
"""主函数""" | ||
maze = [[0] * COLS for _ in range(ROWS)] | ||
reset(maze) | ||
display(maze) | ||
find_way(maze) | ||
print('没有出路!!!') | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" | ||
骑士巡逻 | ||
""" | ||
import sys | ||
|
||
SIZE = 8 | ||
|
||
|
||
def display(board): | ||
"""显示棋盘""" | ||
for row in board: | ||
for col in row: | ||
print(f'{col}'.rjust(2, '0'), end=' ') | ||
print() | ||
|
||
|
||
def patrol(board, i=0, j=0, step=1): | ||
"""巡逻""" | ||
if 0 <= i < SIZE and 0 <= j < SIZE and board[i][j] == 0: | ||
board[i][j] = step | ||
if step == SIZE * SIZE: | ||
display(board) | ||
sys.exit(0) | ||
patrol(board, i + 1, j + 2, step + 1) | ||
patrol(board, i + 2, j + 1, step + 1) | ||
patrol(board, i + 2, j - 1, step + 1) | ||
patrol(board, i + 1, j - 2, step + 1) | ||
patrol(board, i - 1, j - 2, step + 1) | ||
patrol(board, i - 2, j - 1, step + 1) | ||
patrol(board, i - 2, j + 1, step + 1) | ||
patrol(board, i - 1, j + 2, step + 1) | ||
board[i][j] = 0 | ||
|
||
|
||
def main(): | ||
"""主函数""" | ||
board = [[0] * SIZE for _ in range(SIZE)] | ||
patrol(board) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
size = 25 | ||
|
||
for i in range(size): | ||
for j in range(size): | ||
if i % 2 == 1 or j % 2 == 1: | ||
print('■', end='') | ||
else: | ||
print('□', end='') | ||
print() | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.