首页 > 编程语言 > 详细

python小程序5

时间:2015-12-13 02:15:28      阅读:212      评论:0      收藏:0      [点我收藏+]

程序5:输入三个整数x,y,z,请把这三个数由小到大输出。


脚本1

分析:python的列表本身就有自己的sort排序,把数值放放列表,直接排序即可


L=[]

for n in ‘xyz‘:

    print "input",n,":"

    num=int(raw_input())

    L.append(num)

L.sort()

print L



脚本2:把这几个数字直接赋值,然后做对比

x=int(raw_input(‘x:‘))

y=int(raw_input(‘y:‘))

z=int(raw_input(‘z:‘))

if x>y:

    if x>z and y>z:

        print z,y,x

    elif x>z and y<z:

        print y,z,x

    else:

        print y,x,z

else:

    if x>z and y>z:

        print z,x,y

    elif x<z and y>z:

        print x,z,y

    else:

        print x,y,z


python小程序5

原文:http://lijixing.blog.51cto.com/4464145/1722401

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!