zoukankan      html  css  js  c++  java
  • 核心编程答案(第五章)

    5-3

    def LevelTest(score):
        if 90 <= score <= 100:
            return 'A'
        elif 80 <= score < 90:
            return 'B'
        elif 70 <= score < 80:
            return 'C'
        elif 60 <= score < 70:
            return 'D'
        elif score < 60:
            return 'F'
        else:
            return 'NO FOUND'
    
    score = raw_input('Please enter you score: ')
    score = int(score)
    print LevelTest(score)

     5-4

    def Runnian(year):
        if (year % 4 == 0) and (year % 100 != 0) or year % 400 == 0:
            return 'Is runnian!'
        else:
            return 'Is not runnin'
    
    year = int(raw_input('Please enter the year: '))
    print Runnian(year)

     5-5

    #!/usr/bin/env python
    # encoding: utf-8
    
    
    def Zuishaofenpei(num):
        n251 = 0
        n101 = 0
        n51 = 0
        n11 = 0
        while True:
            if num > 25:
                n25 = divmod(num, 25)
                if n25[0] > 0:
                    num = n25[1]
                    n251 = n25[0]
            if 25 > num > 10:
                n10 = divmod(num, 10)
                if n10[0] > 0:
                    num = n10[1]
                    n101 = n10[0]
            if 10 > num > 5:
                n5 = divmod(num, 5)
                if n5[0] > 0:
                    num = n5[1]
                    n51 = n5[0]
            if num < 5:
                n1 = divmod(num, 1)
                n11 = n1[0]
            return '25 cent is %d
    10 cent is %d
    5 cent is %d
    1 cent is %d' % (n251, n101, n51, n11)
    inputCent = int(raw_input('Please input the cent:'))
    print Zuishaofenpei(inputCent)

    5-6

    #!/usr/bin/env python
    # encoding: utf-8
    
    
    def Jisuan(expressions):
        try:
            exlist = expressions.split(' ')
            num1 = float(exlist[0])
            operations = exlist[1]
            num2 = float(exlist[2])
            if operations == '+':
                return num1 + num2
            elif operations == '-':
                return num1 - num2
            elif operations == '*':
                return num1 * num2
            elif operations == '/':
                return num1 / num2
            elif operations == '%':
                return num1 % num2
            elif operations == '**':
                return num1 ** num2
            else:
                return 'please put like this:N1 * N2'
        except IndexError:
                return 'please put like this:N1 * N2'
        except ValueError:
                return 'please put like this:N1 * N2'
    
    expressions = raw_input('please input:')
    print Jisuan(expressions)

     5-11

    #!/usr/bin/env python
    # encoding: utf-8
    
    
    def shifouzc(num1, num2):
        if num1 >= num2:
            if num1 % num2 == 0:
                return True
            else:
                return False
        if num2 >= num1:
            if num2 % num1 == 0:
                return True
            else:
                return False
    
    inputnum = raw_input('please inpput tow num separated by spaces: ')
    inputnum1 = inputnum.split(' ')
    num1 = int(inputnum1[0])
    num2 = int(inputnum1[1])
    print shifouzc(num1, num2)
  • 相关阅读:
    Django基础六之ORM中的锁和事务
    Django学习之model进阶
    Django基础八之cookie和session
    Django基础五之django模型层(二)多表操作
    Django基础五之django模型层(一)单表操作
    Django基础四之模板系统
    webpack最佳入门实践系列(4)
    webpack最佳入门实践系列(3)
    webpack最佳入门实践系列(2)
    webpack最佳入门实践系列(1)
  • 原文地址:https://www.cnblogs.com/ohmydenzi/p/5459245.html
Copyright © 2011-2022 走看看