員工信息表
python
用戶能夠模糊查詢員工信息iphone
顯示匹配了多少條,匹配字符須要高亮顯示ide
#!/usr/bin/env python #coding:utf-8 #author:yangyue import sys count = 0 key = raw_input(u'請輸入要查詢的關鍵字:') if key == 'q': sys.exit print '已退出程序' else : f = file('file.txt') for line in f.readlines(): if line.find(key) != -1: print line.replace(key,'\033[31;1m %s \033[0m' %key) count += line.count(key) print '\n' print u'共匹配到',count,'次'
2. 購物車程序spa
要求用戶輸入工資,而後打印購物菜單ip
用戶能夠不斷的購買商品,直到錢不夠爲止utf-8
退出時格式化打印用戶已購買的商品和剩餘金額ci
#!/usr/bin/env python #coding:utf-8 #author:yangyue import os shopping_list = {'iphone':6000,'ipad':2000,'ipod':1000} print '歡迎來到購物商城!' salary = int(raw_input(u'請輸入您的工資單:')) while salary >= 1000: for i in shopping_list: print i, shopping_list[i] shop = raw_input(u'\n請選擇你要購買的商品:') a = shopping_list.has_key(shop) f = file('shopping','w') f = file('shopping','a') f.write(shop) f.write('\n') if a == True: salary -= shopping_list[shop] if salary >= 0: print u'你如今的餘額爲','\033[31;1m %s \033[0m' %salary,u'元' # f.write('%s,%s\n' %(shop,shopping_list[shop])) # f.write('\n') con = str(raw_input(u'還想繼續購物嗎?(y/n)')) if con == 'n': #f.write(str(salary)) f.close() print u'您已退出購物商城' print u'您所購買的商品爲:' f = file('shopping','r') for line in f.readlines(): print line, print u'您的餘額爲:\033[31;1m %s \033[0m' %salary break else: print '沒有此商品' else: print '\n您的餘額不足,不能繼續購物!'