摘要:
# 一个简单的数据库 # 字典使用人名作为键。每个人用另一个字典来表示,其键'phone'和'addr'分别表示它们的电话号码和地址。 people = { 'Alice':{ 'phone': '2341', 'addr': 'Foo drive 23' }, 'Beth':{ 'phone': '9102... 阅读全文
posted @ 2016-12-16 23:05
苏古勒哈达
阅读(161)
评论(0)
推荐(0)
摘要:
# 使用给定的宽度打印格式化后的价格列表 width = (int)(input('Please enter width:')) price_width = 10 item_width = width - price_width header_format = '%-*s%*s' format = '%-*s%*.2f' print ('=' * width) prin... 阅读全文
posted @ 2016-12-16 19:11
苏古勒哈达
阅读(170)
评论(0)
推荐(0)
摘要:
# 检查用户名和PIN码 database = [ ['albert', '1234'], ['dilbert', '4242'], ['smith', '7524'], ['jones', '9843'] ] username = input('User name:') pin = input('PIN code:') if [username, ... 阅读全文
posted @ 2016-12-16 15:27
苏古勒哈达
阅读(114)
评论(0)
推荐(0)
摘要:
# 以正确的宽度在居中的“盒子”内打印一个句子 # 注意,整数除法运算符(//)只能用在Python 2.2及后续版本,在之前的版本中,只使用普通除法(/) sentence = input("Sentence:") screen_width = 80 text_width = len(sentence) box_width = text_width + 6 left_margin = (s... 阅读全文
posted @ 2016-12-16 14:38
苏古勒哈达
阅读(184)
评论(0)
推荐(0)
摘要:
# 对http://www.something.com形式的URL进行分割 url = input("Please enter the URL:") domain = url[11:-4] print ("Domain name:" + domain) 阅读全文
posted @ 2016-12-16 14:16
苏古勒哈达
阅读(78)
评论(0)
推荐(0)
浙公网安备 33010602011771号