Latest web development tutorials

Python includes exercises 89

Python 100 Li Python 100 Li

Title: The adoption of a public telephone to transfer data, the data is an integer of four, and in the transfer process is encrypted, the encryption rules are as follows: Each figures plus 5, then divided by 10, the remainder in place of the numbers, then swap the first and fourth, second and third exchange.

Program Analysis: None.

Source Code:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

from sys import stdout
if __name__ == '__main__':
    a = int(raw_input('input a number:\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 above example output is:

input a number:
89
4355

Python 100 Li Python 100 Li