摘要: #匹配电话,例如:415-555-4242 def isPhoneNumber(text): if len(text) != 12: return False for i in range(0, 3): if not text[i].isdecimal(): return False if text[3] != '-... 阅读全文
posted @ 2019-03-13 16:21 晨光曦微 阅读(465) 评论(0) 推荐(0) 编辑
摘要: import traceback try: raise Exception('这是一个错误信息') except: errFile=open('err.txt','w') errFile.write(traceback.format_exc()) errFile.close() print('错误信息已经写入err.txt文件中') 阅读全文
posted @ 2019-03-13 16:20 晨光曦微 阅读(204) 评论(0) 推荐(0) 编辑
摘要: import requests,bs4,os #利用 requests 模块下载页面 url='http://xkcd.com' os.makedirs('xkcd', exist_ok=True) #创建一个文件夹xkcd while not url.endswith('#'): res=requests.get(url) res.raise_for_status() #没... 阅读全文
posted @ 2019-03-13 16:19 晨光曦微 阅读(714) 评论(0) 推荐(0) 编辑
摘要: class Dog(): def __init__(self,name,age): self.name=name self.age=age def sit(self): print(self.name.title()+' 现在坐下了') def roll_over(self): print(self.name... 阅读全文
posted @ 2019-03-13 16:18 晨光曦微 阅读(258) 评论(0) 推荐(0) 编辑
摘要: def hello(): print('Howdy!') print('Howdy!!!') print('Hello there.') hello() 阅读全文
posted @ 2019-03-13 16:17 晨光曦微 阅读(196) 评论(0) 推荐(0) 编辑
摘要: import random heads = 0 for i in range(1, 1001): if random.randint(0, 1) == 1: heads = heads + 1 if i == 500: print('Halfway done!') print('Heads came up ' + str(heads) + ' ti... 阅读全文
posted @ 2019-03-13 16:15 晨光曦微 阅读(129) 评论(0) 推荐(0) 编辑
摘要: ##小程序,计算一个字符串中每个字符出现的次数+ import pprint message = 'It was a bright cold day in April, and the clocks were striking thirteen.' count = {} for character in message: count.setdefault(character, 0) ... 阅读全文
posted @ 2019-03-13 16:14 晨光曦微 阅读(677) 评论(0) 推荐(0) 编辑
摘要: ''' picnicItems 野餐用品清单 picnicItems sandwiches.................... 4apples........................ 12cups.......................... 4cookies........... 阅读全文
posted @ 2019-03-13 16:13 晨光曦微 阅读(223) 评论(0) 推荐(0) 编辑
摘要: def boxPrint(symbol, width, height): if len(symbol) != 1: raise Exception('Symbol(符号) must be a single character string.') if width <= 2: raise Exception('Width must be greate... 阅读全文
posted @ 2019-03-13 16:12 晨光曦微 阅读(317) 评论(0) 推荐(0) 编辑
摘要: birthdays = {'Alice': 'Apr 1', 'Bob': 'Dec 12', 'Carol': 'Mar 4'} while True: print('Enter a name: (blank to quit)') name = input() if name == '': break if name in birthdays: ... 阅读全文
posted @ 2019-03-13 16:09 晨光曦微 阅读(228) 评论(0) 推荐(0) 编辑