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

Python Exercise Example 66

Python Exercise Example 66

Python 100 Examples Python 100 Examples

**Problem:** Enter three numbers a, b, c and output them in order of magnitude.

**Analysis:** None.

Program source code:

Example

#!/usr/bin/python

-- coding: UTF-8 --

if

name

==

'

main

'

:

n1

=

int

(

raw_input

(

'

n1 = :

\n

'

)

)

n2

=

int

(

raw_input

(

'

n2 = :

\n

'

)

)

n3

=

int

(

raw_input

(

'

n3 = :

\n

'

)

)

def

swap

(

p1

,

p2

)

:

return

p2

,

p1

if

n1

n2

:

n1

,

n2

=

swap

(

n1

,

n2

)

if

n1

n3

:

n1

,

n3

=

swap

(

n1

,

n3

)

if

n2

n3

:

n2

,

n3

=

swap

(

n2

,

n3

)

print

n1

,

n2

,

n3

The output of the above example is:


n1 = :
123
n2 = :
456
n3 = :
789
123 456 789

Python 100 Examples Python 100 Examples