# 两个Python练习题

1．假设校园电费是0.6元/千瓦时，输入这个月使用了多少千瓦时的点，算出你要交的电费
。假如你只有1元和1毛的硬币，请问各需要多少1元和1毛的硬币。

```def main():
pq = input('please input the power quantity:')
price = 0.6
amt = pq * price * 10
i = int(amt) / 10
j = int(amt) % 10 / 1
print 'It will spend you %d yuan and %d jiao' % (i,j)```

>>> main()
It will spend you 19 yuan and 1 jiao

2.假设已加密系统采用替换法进行加密，替换的规则如下：

1.  使用find
```def decode():
strKey = 'abcdefghijklmnopqrstuvwxyz'
strValue = 'qwertyuiopasdfghjklzxcvbnm'
strIn = raw_input('please enter some words:')
strOut = ''
for i in range(len(strIn)):
strOut += strValue[strKey.find(strIn[i])]
print 'decode result is :%s' % (strOut)```

>>> decode()
decode result is :qwetytu

2.使用字典

```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)```

>>> decode()
decode result is :itssgvgksr

• 0

开心

• 0

板砖

• 0

感动

• 0

有用

• 0

疑问

• 0

难过

• 0

无聊

• 0

震惊