两个Python练习题
1.假设校园电费是0.6元/千瓦时,输入这个月使用了多少千瓦时的点,算出你要交的电费
。假如你只有1元和1毛的硬币,请问各需要多少1元和1毛的硬币。
输入输出:
输入这个月使用的电量:11
电费:6.6
共需6张1元和6张1毛
def docode(): strKey = 'abcdefghijklmnopqrstuvwxyz' strValue = 'qwertyuiopasdfghjklzxcvbnm' strIn = raw_input('please enter some words:') dictDecode = {} strOut = '' for i in range(len(strKey)): dictDecode[strKey[i]] = strValue[i] for i in range(len(strIn)): strOut += dictDecode[strIn[i]] print 'decode result is :%s' % (strOut)