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
# 1、编写一个函数完成密码生成器的功能,输入参数有密码长度和密码组成的内容,密码组成的内容可以有大写字母(A-Z)、小写字母(a-z)、数字(0-9)、特殊符号(~!@#$%^&*()),返回值为按照用户要求生成的随机密码 | |
def passwd_gen(p_len, lower_case=True, upper_case=True, number=True, special_char=True): | |
import string, random | |
lower_case_set = set(list(string.ascii_lowercase)) | |
upper_case_set = set(list(string.ascii_uppercase)) | |
number_set = set([x for x in range(10)]) | |
special_char_set = set(list('~!@#$%^&*()')) | |
user_choice = set() | |
if lower_case: | |
user_choice = user_choice | lower_case_set |
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
# 1、写一个函数:获取用户输入的名字(name)和年龄(age),计算一下该用户到哪一年(返回值)为100岁,并打印结果”{用户名字}在XXXX年为100岁” | |
def get_year_of_hundred(): | |
name = input('请输入您的名字:') | |
age = int(input('请输入您当前的年龄:')) | |
which_year = 100 + 2018 - age | |
print(f'{name} 在 {which_year} 年为 100 岁') | |
return which_year | |
get_year_of_hundred() |
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
# 1、编写一个函数输出乘法口诀表,执行结果如图所示(提示:print 默认输出后会换行,可以通过 print 参数控制是否换行) | |
for i in range(1, 10): | |
for j in range(1, i + 1): | |
print('{}*{}={}'.format(i, j, i*j), end='\t') | |
print() | |
################################ | |
for i in range(1, 10): | |
for j in range(1, i + 1): | |
end_flag = '\n' if i == j else '\t' | |
print(f'{i}*{j}={i*j}', end=end_flag) |
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
# 1、将字符串'hello, world'中的 l 替换为 * | |
'hello, world'.replace('l', '*') | |
# 2、现有字符串 'Good' ,期望结果 'good!good!good!',至少用两种方法实现 | |
string = 'Good'.lower() + '!' | |
string + string + string | |
############################## | |
string = 'Good' | |
string = string.lower() + '!' | |
string * 3 |
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
def all_indices(value, qlist): | |
indices = [] | |
idx = -1 | |
while True: | |
try: | |
idx = qlist.index(value, idx + 1) | |
indices.append(idx) | |
except ValueError: | |
break | |
return indices |
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
def remove_duplicates_of_list(lst): | |
if len(lst) < 2: | |
return lst | |
d = {} | |
for i in xrange(len(lst)): | |
if lst[i] in d.values(): | |
continue | |
d.update({i: lst[i]}) | |
return [lst[key] for key in sorted(d.keys())] |
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
import unittest | |
def get_of_data(data, key): | |
if type(key) is int: | |
if key < len(data[1]): | |
k = data[1][key] | |
return data[0][k] | |
raise IndexError('The index is out of range.') | |
elif type(key) is str: | |
return data[0][key] |
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
if __name__ == "__main__": | |
import datetime | |
today = None#开始日期 | |
forgettingCurve = [0, 1, 2, 4, 7, 15, 30]#在这里设置您的记忆曲线间隔天数,0表示无间隔 | |
title = "UnitName FirstDate SecondDate ThirdDate FourthDate FifthDate SixthDate SeventhDate" | |
print("Your vocabulary memorization schedule as following\n%s\n%s" % ("="*100, title)) | |
for num in range(1, 22): | |
if today is None and num == 1: | |
today = datetime.date.today() | |
else: |