Python自学练习

习题5.3

根据分数输出级别,如何对条件判断语句进行简化

a=raw_input('Please input the score:\n>>>')

def level(a):

    if a >= 90 <=100:

        return 'A'

    elif a >= 80 <=89:

        return 'B'

    elif a >= 70 <=79:

        return 'C'

    elif a >= 60 <=69:

        return 'D'

    else:

        return 'F'

print level(a)

习题5.5

m = input('Please input the amount:\n>>>')

print type(m)

m *= 100

a = m // 25

b = (m % 25) // 10

c = ((m % 25) % 10 // 5)

d = ((m % 25) % 10 % 5)

print m, 'can be changed into %d 25,%d 10,%d 5,%d 1' % (a, b, c, d)


你可能感兴趣的:(python,自学)