2016年12月16日
摘要: # 一个简单的数据库 # 字典使用人名作为键。每个人用另一个字典来表示,其键'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 苏古勒哈达 阅读(169) 评论(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)
  2016年12月11日
摘要: 题目要求:输入N个数,输出该数列中第k个最大者。 程序源码: 阅读全文
posted @ 2016-12-11 18:31 苏古勒哈达 阅读(113) 评论(0) 推荐(0)
  2016年12月10日
摘要: 题目要求: 定义一个二维数组保存 10个学生的5门课成绩,分别用函数实现:(1)input():输入每个学生的成绩;(2)output():输出每个学生的成绩;(3)aver_stu():计算并输出每个学生的平均分;(4)aver_cour():计算并输出每门课的平均分;(5)highest():找 阅读全文
posted @ 2016-12-10 22:43 苏古勒哈达 阅读(263) 评论(0) 推荐(0)
摘要: 题目要求: 编程实现功能:将4行4列数组的左下三角设置为下图所示的数据。43 7 2 6 91 5 8 10 程序源码: 阅读全文
posted @ 2016-12-10 16:36 苏古勒哈达 阅读(126) 评论(0) 推荐(0)
摘要: 题目要求:国王将金币作为工资,发放给忠诚的骑士。第1天,骑士收到一枚金币;之后两天(第2天和第3天)里,每天收到两枚金币;之后三天(第4、5、6天)里,每天收到三枚金币;之后四天(第7、8、9、10天)里,每天收到四枚金币……这种工资发放模式会一直这样延续下去:当连续n天每天收到n枚金币后,骑士会在 阅读全文
posted @ 2016-12-10 10:51 苏古勒哈达 阅读(380) 评论(0) 推荐(0)