Python Practice Example 89
Problem:A company uses a public telephone to transmit data. The data is a four-digit integer that is encrypted during transmission. The encryption rules are as follows: Add 5 to each digit, then replace the digit with the remainder when the sum is divided by 10. Then swap the first and fourth digits, and swap the second and third digits.
Program analysis:None.
Program source code:
Example
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from sys import stdout
if __name__ == '__main__':
a = int(raw_input('Enter four numbers:\n'))
aa = []
aa.append(a % 10)
aa.append(a % 100 / 10)
aa.append(a % 1000 / 100)
aa.append(a / 1000)
for i in range(4):
aa[i] += 5
aa[i] %= 10
for i in range(2):
aa[i],aa[3 - i] = aa[3 - i],aa[i]
for i in range(3,-1,-1):
stdout.write(str(aa[i]))
The output of the above example is:
输入四个数字: 1234 9876Other extensions
Python 100 Examples