generated from west2-online-reserve/collection-template
-
Notifications
You must be signed in to change notification settings - Fork 45
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
1 parent
608a9d4
commit 96446c1
Showing
8 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
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,23 @@ | ||
from functools import wraps | ||
import time | ||
def decorator(fun): | ||
@wraps(fun) | ||
def wrap_the_function(): | ||
print(fun.__name__) | ||
T1 = time.perf_counter() | ||
fun() | ||
T2 = time.perf_counter() | ||
during_time = T2-T1 | ||
print('Starting time: %f \nEnding time: %f \nDuring time: %f(s)'%(T1,T2,during_time)) | ||
return wrap_the_function | ||
|
||
@decorator | ||
def funtion_need_to_be_decorated(): | ||
for i in range(100*100): | ||
pass | ||
|
||
funtion_need_to_be_decorated() | ||
|
||
|
||
import os | ||
print(os.getcwd()) |
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,77 @@ | ||
'''用所学的知识写一个斗地主随机发牌程序,将每个人的发牌以及多的三张牌的结果分别按照从大到小的顺序输出到player1.txt,player2.txt,player3.txt,others.txt四个文件中''' | ||
'''Using H S C D to substitude hearts, spades, clubs, and diamonds''' | ||
import random | ||
import os | ||
import re | ||
|
||
def make_folder(name): | ||
'''to make a folder''' | ||
path = os.getcwd() | ||
folder = path + r'\\'+name | ||
if not os.path.exists(folder): | ||
os.makedirs(folder) | ||
print('--- Make a new folder successfully ---') | ||
else: | ||
print("--- There is this folder! ---") | ||
return folder | ||
|
||
def substitude(card): | ||
''' to substitude some nums to character''' | ||
num = re.findall('\d+',card)[0] | ||
if num == '1': | ||
ncard = card.replace(num,'A') | ||
elif num == '11': | ||
ncard = card.replace(num,'J') | ||
elif num == '12': | ||
ncard = card.replace(num,'Q') | ||
elif num == '13': | ||
ncard = card.replace(num,'K') | ||
elif num == '100': | ||
ncard = card.replace(num,'joker') | ||
elif num == '200': | ||
ncard = card.replace(num,'JOKER') | ||
else: | ||
ncard = card | ||
return ncard | ||
|
||
cards=[] | ||
for i in range(1,14): | ||
for suit in ["-H","-S","-C","-D"]: | ||
cards.append(str(i)+suit) | ||
cards.append('100')#joker=100 | ||
cards.append('200')#JOKER=200 | ||
random.shuffle(cards) | ||
|
||
player1,player2,player3=[],[],[] | ||
players = [player1,player2,player3] | ||
landowner = cards[-3:] | ||
|
||
n=0 | ||
while n<= len(cards)-3: | ||
for player in players: | ||
player.append(cards[n]) | ||
n+=1 | ||
|
||
player1.sort(reverse=True,key=lambda l: int(re.findall('\d+',l)[0])) | ||
player2.sort(reverse=True,key=lambda l: int(re.findall('\d+',l)[0])) | ||
player3.sort(reverse=True,key=lambda l: int(re.findall('\d+',l)[0])) | ||
folder = make_folder('Q2_poke_game') | ||
|
||
with open(folder + '\Player1.txt','w') as df: | ||
for card in player1: | ||
card = substitude(card) | ||
df.write(card+' ') | ||
|
||
with open(folder + '\Player2.txt','w') as df: | ||
for card in player2: | ||
card = substitude(card) | ||
df.write(card+' ') | ||
|
||
with open(folder + '\Player3.txt','w') as df: | ||
for card in player3: | ||
card = substitude(card) | ||
df.write(card+' ') | ||
|
||
print('done') | ||
|
||
|
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 @@ | ||
Q-H Q-D 10-S 10-H 10-C 9-C 9-D 8-S 7-D 6-C 6-S 6-H 4-H 4-S 3-S A-C A-S A-H |
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 @@ | ||
JOKER K-C Q-S J-C J-H J-S 9-H 8-D 8-C 8-H 7-H 6-D 5-D 5-C 5-S 5-H 3-H 3-C |
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 @@ | ||
joker K-S K-D K-H Q-C J-D 10-D 9-S 7-C 7-S 4-C 4-D 3-D 2-C 2-S 2-D 2-H A-D |
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 @@ | ||
'''写一个列表推导式,生成一个5*10的矩阵,矩阵内的所有值为1,再写一个列表推导式,把这个矩阵转置''' | ||
lst1 = [[1 for i in range(10)]for o in range(5)] | ||
print(lst1) | ||
lst2 = [[lst1[0][0] for i in range(len(lst1))] for o in range(len(lst1[0]))] | ||
print(lst2) |
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,50 @@ | ||
'''了解类的魔术方法(Magic Method)。创建类MyZoo,实现以下功能: | ||
具有字典anmials,动物名称作为key,动物数量作为value | ||
实例化对象的时候,输出"My Zoo!" | ||
创建对象的时候可以输入字典进行初始化,若无字典传入,则初始化anmials为空字典 | ||
myzoooo = MyZoo({"pig":5,'dog':6}) | ||
myzoooo = MyZoo() | ||
print(myzoooo) 输出 动物名称和数量 | ||
比较两个对象是否相等时,只要动物种类一样,就判断相等: | ||
输入: | ||
myzoooo1 = MyZoo({'pig':1}) | ||
myzoooo2 = MyZoo({'pig':5}) | ||
print(myzoooo1 == myzoooo2) | ||
输出: | ||
My Zoo! | ||
My Zoo! | ||
True | ||
len(myzoooo) 输出所有动物总数''' | ||
|
||
class MyZoo(): | ||
def __init__(self, dic=None): | ||
if dic is None: | ||
dic = {} | ||
print("My Zoo!") | ||
self.dic = dic | ||
|
||
def __str__(self): | ||
return str(self.dic) | ||
|
||
def __len__(self): | ||
n = 0 | ||
for value in self.dic.values(): | ||
n+=value | ||
return n | ||
|
||
def __eq__(self, other): | ||
keys1=[] | ||
keys2=[] | ||
for key in self.dic.keys(): | ||
keys1.append(key) | ||
for key in other.dic.keys(): | ||
keys2.append(key) | ||
return sorted(keys1) == sorted(keys2) | ||
|
||
|
Empty file.