zoukankan      html  css  js  c++  java
  • python3 练习题100例 (五)

    题目五:输入三个整数x,y,z,请把这三个数由小到大输出。

    #!/usr/bin/env python3
    # -*- coding: utf-8 -*-
    
    """ 题目五:输入三个整数x,y,z,请把这三个数由小到大输出。"""
    
    __author__ = 'Fan Lijun'
    
    one = eval(input('请输入三个数:'))
    two = eval(input('请输入三个数:'))
    three = eval(input('请输入三个数:'))
    
    #方法一:使用内置排序函数
    lst = [one, two, three]
    print(lst.sort())
    
    #方法二:我自己写一个,锻炼一下if  else
    lst2 = []
    
    #获得最小数
    def minNumber(one, two, three):
        if one < two:
            if one < three:
                lst2.append(one)
            else:
                lst2.append(three)
        else:
            if two < three:
                lst2.append(two)
            else:
                lst2.append(three)
    
    def maxNumber(one, two, three):
        if one > two:
            if one > three:
                lst2.append(one)
            else:
                lst2.append(three)
        else:
            if two > three:
                lst2.append(two)
            else:
                lst2.append(three)
    minNumber(one, two, three)
    maxNumber(one, two, three)
    
    if lst2[0] == one:
        if lst2[1] == two:
            lst2.insert(1, three)
        else:
            lst2.insert(1, two)
    elif lst2[0] == two:
        if lst2[1] == three:
            lst2.insert(1, one)
        else:
            lst2.insert(1, three)
    else:
        if lst2[1] == two:
            lst2.insert(1, one)
        else:
            lst2.insert(1, three)
    
    print(lst2)
    

      

  • 相关阅读:
    lufylegend:图形变形3
    javascript: Math.sin() cos() 用法
    lufylegend:图形变形2
    lufylegend:图形变形1
    lufylegend:图片的加载和显示
    lufylegend基础知识1
    canvas使用3
    canvas使用2
    canvas使用1
    javascript:addEventListener
  • 原文地址:https://www.cnblogs.com/LoveBeautiful/p/9896490.html
Copyright © 2011-2022 走看看