python核心编程第二版 2.11

题目描述:文本输入,功能选择

print '请输入相应功能的标号 1:求输入5个数之和。2:求输入5个数的平均值。3:将5个数大小排序。4:退出程序'
a = int(raw_input())
p = True
total = 0
total1 = 0
average = 0
while p:
    if a == 1:
        #求和的功能代码
        for i in range(0,5):
            print '请输入第%d位数字' %(i+1)
            total = total + int(raw_input())
        print'输入的5个数字和为:%d'%total
        p = False
        
    elif a == 2:
        #求均值的功能代码
        for i in range(0,5):
            print '请输入第%d为数字' %(i+1)
            total1 = total1 + float(raw_input())
        print '输入的5个数字的平均值为:%f' %(total1/5)
        p = False
        
    elif a == 3:
        #排序的功能代码
        
        p = False
        
    elif a == 4:
        print '程序结束'
        p = False
        
    else:
        print '你输入的数字有误,请重新输入'
        a = int(raw_input())
        

猜你喜欢

转载自blog.csdn.net/qq_37599517/article/details/81062240