Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Exercise Example 89

Python Exercise Example 89

Python 100 Examples Python 100 Examples

**Problem:** A company uses public telephones to transmit data. The data is a four-digit integer and is encrypted during transmission. The encryption rules are as follows: add 5 to each digit, then replace the digit with the remainder of the sum divided by 10, then swap the first and fourth digits, and swap the second and third digits.

**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:


Enter four numbers:
1234
9876

Python 100 Examples Python 100 Examples