Python题库——答案

程序基本结构计分作业

# encoding: utf-8
# !/usr/bin/python
"""
@Filename:作业1
@Author: Jiaming
@Create date:2019.9.12
@Mail:[email protected]
@Blog:https://blog.csdn.net/weixin_39541632
@Description:
"""
import random
from fractions import Fraction


def homework1():
    """
    :return:
    """
    """
    1:剪刀
    2:石头
    3:布
    2>1>3>2
    """
    count = 0
    while True:
        user = input("请输入1~3分别表示剪刀、石头和布:")
        windows = str(random.randint(1, 3))
        if user == '1' and windows == '3':
            count += 1
            print("计算机出布,您出剪刀,恭喜您赢了!")
        elif user == '2' and windows == '1':
            count += 1
            print("计算机出剪刀,您出石头,恭喜您赢了!")
        elif user == '3' and windows == '2':
            count += 1
            print("计算机石头,您出布,恭喜您赢了!")

        if user == '3' and windows == '1':
            print("计算机出剪刀,您出布,计算机赢。")
        elif user == '1' and windows == '2':
            print("计算机出石头,您出剪刀,计算机赢。")
        elif user == '2' and windows == '3':
            print("计算机出布,您出石头,计算机赢。")

        if user == '3' and windows == '3':
            print("平局!")
        elif user == '1' and windows == '1':
            print("平局!")
        elif user == '2' and windows == '2':
            print("平局!")

        if count == 3:
            return


def homework2():
    """
    :return:
    """
    n = int(input("请输入练习题数量:"))
    count = 0
    while count != n:
        x = random.randint(10, 99)
        y = random.randint(10, 99)
        while True:
            answer = input("{0} + {1}= ?".format(x, y))
            if int(answer) != x + y:
                print("不对,请重新计算")
            else:
                count += 1
                print()
                break
    print("恭喜你完成此次加法练习!")


def homework3():
    """
    :return:
    """
    # x/y
    inputs = input().split()
    x1, y1 = map(int, inputs[0].split('/'))
    x2, y2 = map(int, inputs[1].split('/'))
    a = Fraction(x1, y1)
    b = Fraction(x2, y2)
    print(a + b)


def homework4():
    """
    :return:
    """
    x = int(input())
    l = []
    while x:
        l.append(x % 10)
        x //= 10
    l.reverse()
    for i in l:
        print(i, end=" ")


def homework5():
    """
    :return:
    """
    F = [1, 1]
    n = int(input())
    if n > 2:
        for i in range(n - 2):
            F.append(F[i] + F[i + 1])
    print(F[-1])


def homework6():
    """
    :return:
    """
    s = input()
    l = list(s)
    l.reverse()
    if s == ''.join(l):
        print("{0} {1}".format(s, "yes"))
    else:
        print("{0} {1}".format(s, "no"))


def homework71(n):
    """
    :param n:
    :return:
    """
    for i in range(2, n, 1):
        if n % i == 0:
            return False
    return True


def homework7():
    """
    :return:
    """
    n = int(input())
    for i in range(2, n // 2, 1):
        if homework71(i) is True and homework71(n - i) is True:
            print(i, n - i)


def homework8():
    """
    :return:
    """
    a, b = input().split()
    c = ""
    c = a[0] + b[0] + a[1] + b[1]
    print(c)


def homework9():
    """
    :return:
    """
    l = ["rat", "ox", "tiger", "rabbit", "dragon", "snake",
         "horse", "sheep", "monkey", "rooster", "dog", "pig"]
    year = int(input())
    if year >= 2018:
        print("{0} {1}".format(year, l[(year-2018+10)%12]))
    else:
        print("{0} {1}".format(year, l[-(2018-year+2)%12]))


def homework10():
    """
    :return:
    """
    x1, y1 = map(float, input().split())
    x2, y2 = map(float, input().split())
    if y1 / x1 < y2 / x2:
        print(int(x1),round(y1,1))
    else:
        print(int(x2), round(y2,1))

if __name__ == "__main__":
    homework10()

顺序和分支结构练习题

# encoding: utf-8
# !/usr/bin/python
"""
@Filename:顺序和分支结构练习题
@Author: Jiaming
@Create date:2019/9/19
@Mail:[email protected]
@Blog:https://www.cnblogs.com/jiamingZ
@Description:
"""
import math


def no1():
    number = int(input())
    if number % 3 == 0 and number % 5 == 0 and number % 7 == 0:
        print('a', number)
    elif number % 3 != 0 and number % 5 != 0 and number % 7 != 0:
        print('c', number)
    else:
        print('b', number)


def no2():
    l = sorted(map(int, input().split()))
    print("{0} {1}".format(l[0], "me"))
    print("{0} {1}".format(l[1], "mommy"))
    print("{0} {1}".format(l[2], "daddy"))


def no3():
    a, b, c = map(float, input().split())
    # print(a,b,c)
    delta = b * b - 4 * a * c
    if delta > 0:
        x1 = -b + math.sqrt(b * b - 4 * a * c)
        x2 = -b - math.sqrt(b * b - 4 * a * c)
        print("x1={0} x2={1}".format('%.2f' %
                                     (x1 / (2 * a)), '%.2f' %
                                     (x2 / (2 * a))))
    elif delta == 0:
        x1 = -b + math.sqrt(b * b - 4 * a * c)
        print("x1=x2={0}".format('%.2f' % (x1 / (2 * a))))
    elif delta < 0:
        x1 = math.sqrt(4 * a * c - b * b) / (2 * a)
        x2 = math.sqrt(4 * a * c - b * b) / (2 * a)
        print("x1={0}+{1}j x2={2}-{3}j".format('%.2f' %
                                               (-b / (2 * a)), '%.2f' %
                                               (x1), '%.2f' %
                                               (-b / (2 * a)), '%.2f' %
                                               (x2)))


def no4():
    a, b, c = map(int, input())
    # print(a,b,c)
    print(a + b + c)


def no5():
    a, b = input().split()
    c = ""
    c = a[0] + b[0] + a[1] + b[1]
    print(c)


def no6():
    x = int(input())
    hour = x // 3600
    x -= hour * 3600
    minute = x // 60
    x -= minute * 60
    second = x
    print("{}:{}:{}".format(hour, minute, second))


def no7():
    x = float(input())
    print("%.2f" % (x * 3.6))


def no8():
    x1, y1, x2, y2 = map(float, input().split())
    print("{0} {1}".format("%.2f" % ((x1 + x2) / 2), "%.2f" % ((y1 + y2) / 2)))


def no9():
    a, b, c = map(int, input())
    if pow(a, 3) + pow(b, 3) + pow(c, 3) == 100 * a + 10 * b + c:
        print("%s%s%s yes" % (a, b, c))
    else:
        print("%s%s%s no" % (a, b, c))


def no10():
    x1, y1, x2, y2 = map(float, input().split())
    print("{0}".format("%.2f" %
                       (math.sqrt(pow((x1 - x2), 2) + pow((y1 - y2), 2)))))


def no11(a,b,c):
    # a, b, c = map(int, input().split())
    if a + b > c and a - b < c and a + c > b and a - c < b and b + c > a and b - c < a:
        # print("{} {} {} yes".format(a,b,c))
        return True
    else:
        # print("{} {} {} no".format(a, b, c))
        return False

def no12():
    x = int(input())
    if x < 1000 and x > 0:
        print("%.0f"%math.sqrt(x))
    else:
        print("{} error".format(x))

def no13():
    year, month, day = map(int, input().split())
    sum = 0
    month -= 1
    while month >= 1:
        if month == 1:
            sum += 31
        elif month == 2:
            if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
                sum += 29
            else:
                sum += 28
        elif month == 3:
            sum += 31
        elif month == 4:
            sum += 30
        elif month == 5:
            sum += 31
        elif month == 6:
            sum += 30
        elif month == 7:
            sum += 31
        elif month == 8:
            sum += 31
        elif month == 9:
            sum += 30
        elif month == 10:
            sum += 31
        elif month == 11:
            sum += 30
        elif month == 12:
            sum += 31
        month -= 1
    print(sum+day)


def no14():
    r, h = map(float, input().split())
    print("%.2f"%(math.pi*r*r*h))

def no15():
    r = float(input())
    print("%.2f" % (4/3*math.pi * r * r * r))

def no16():
    a, b, c = map(float, input().split())
    if no11(a,b,c) == True:
        s = (a + b + c) / 2
        area = math.sqrt(s*(s - a)*(s - b)*(s - c))
        print("%.2f" % area)
    else:
        print("%.2f %.2f %.2f error" % (a, b, c))

def no17():
    x = input()
    if x[-1] == 'F':
        x = float(x[:-1])
        print("F=%.2f"%(1.8*x+32))
    else:
        x = float(x[:-1])
        print("C=%.2f"%((x-32)/1.8))

def no18():
    x = int(input())
    y = 0
    if x < -5:
        y = x + 10
    elif -5<=x<=5:
        y=x/2
    else:
        y = 2*x-10
    print("%.1f"%(y))

def no19():
    a,b,c = map(int, input().split())
    if a >= b and a>=c:
        print(a)
    elif b>=a and b>=c:
        print(b)
    elif c>=a and c>=b:
        print(c)
def no20():
    x, y = map(int, input().split())
    s = 0.3048*x+y/12*0.3048
    if s >=2.25:
        print("%.2f you are tall"%(s))
    elif s>=1.7:
        print("%.2f you are middle"%(s))
    else:
        print("%.2f you are short" % (s))

def no21():
    x,y=map(int, input().split())
    Sy = y*6
    Sx=30*x+0.5*(y)
    if Sy >= Sx:
        print("%.1f"%(Sy-Sx))
    else:
        print("%.1f"%(Sx-Sy))
if __name__ == "__main__":
    no21()

循环相关部分练习题

# encoding: utf-8
# !/usr/bin/python
"""
@Filename:循环相关部分练习题
@Author: Jiaming
@Create date:2019/9/26
@Mail:[email protected]
@Blog:https://www.cnblogs.com/jiamingZ
@Description:
"""
import collections
from fractions import Fraction


def no1():
    """
    :return:
    """
    m = int(input())
    s = 0
    for i in range(1, 4):
        for j in range(6):
            for k in range(7):
                if i + j + k == m:
                    s += 1
    print(s)


def no2():
    """
    :return:
    """
    num, N = map(int, input().split())

    s = ''
    while num:
        s += str(num % N)
        num //= N
    print(''.join(reversed(list(s))))


def no3():
    """
    :return:
    """
    s = input()
    number = 0
    for i in s:
        if i is 'a' or i is 'i' or i is 'u' or i is 'e' or i is 'o':
            number += 1
    print(number)


def no4():
    """
    x/y
    :return:
    """
    n = int(input())
    x = 2
    y = 1
    s = 0
    while n:
        y1 = y
        s += x / y
        y = x
        x = x + y1
        n -= 1
    print("%.2f" % (s))


def no5():
    """
    :return:
    """
    x = int(input())
    l = []
    for i in range(len(str(x))):
        l.append(x % 10)
        x //= 10
    k = 0
    for i in l:
        if i == 0 and k == 0:
            pass
        elif i != 0 or k == 1:
            print(i, end='')
            k = 1


def no6():
    """
    :return:
    """
    x = int(input())
    l = []
    while x:
        l.append(x % 10)
        x //= 10
    l.reverse()
    for i in l:
        print(i, end=' ')


def no71(x):
    """
    :return:
    """
    s = 1
    for i in range(1, x + 1, 1):
        s *= i
    return s


def no7():
    """
    :return:
    """
    n = int(input())
    s = 0
    for i in range(1, n + 1, 1):
        s += no71(i)
    print(s)


def no8():
    """
    :return:
    """
    m, n = map(int, input().split())
    # m < n
    if m > n:
        m, n = n, m
    s = 1
    g = 1
    while s <= m:
        if m % s == 0 and n % s == 0:
            g = s
        s += 1
    print("{} {}".format(g, m * n // g))


def no91(x):
    """
    :return:
    """
    l = []
    for i in range(1, x):
        if x % i == 0:
            l.append(i)
    return l


def no9():
    """
    :return:
    """
    x = int(input())
    l = no91(x)
    if x == sum(l):
        print('{}={}'.format(x, l[0]), end='')
        for i in range(1, len(l)):
            print("+{}".format(l[i]), end='')
    elif x < sum(l):
        print('{}<{}'.format(x, l[0]), end='')
        for i in range(1, len(l)):
            print("+{}".format(l[i]), end='')
    else:
        print('{}>{}'.format(x, l[0]), end='')
        for i in range(1, len(l)):
            print("+{}".format(l[i]), end='')


def no10():
    """
    :return:
    """
    x = int(input())
    s = 1
    while x - 1:
        s = s * 2 + 2
        x -= 1
    print(s)


def no11():
    """
    :return:
    """
    s = input()
    s1 = s2 = s3 = s4 = 0
    for i in range(len(s)):
        if 'z' >= s[i] >= 'a'or 'Z' >= s[i] >= 'A':
            s1 += 1
        elif '9' >= s[i] >= '0':
            s2 += 1
        elif s[i] == ' ':
            s3 += 1
        else:
            s4 += 1
    print("{} {} {} {}".format(s1, s3, s2, s4))


def no12():
    """
    :return:
    """
    F = [1, 1]
    n = int(input())
    if n > 2:
        for i in range(n - 2):
            F.append(F[i] + F[i + 1])
    print(F[-1])


def no13():
    """
    :return:
    """
    m, n = map(int, input().split())
    m1 = m
    n1 = n
    # m > n
    if m < n:
        m, n = n, m
    r = -1
    while r != 0:
        r = m % n
        m = n
        n = r
    print("{} {}".format(m, m1 * n1 // m))


def no14():
    """
    :return:
    """
    n = int(input())
    s = 0
    for i in range(1, n + 1, 1):
        s += 1 / (i * (i + 1))
    print("%.5f" % (s))


def no151(x):
    """
    :param x:
    :return:
    """
    for i in range(2, x, 1):
        if x % i == 0:
            return False
    return True


def no15():
    """
    :return:
    """
    m = int(input())
    if no151(m) is True:
        print("{} {}".format(m, "Yes"))
    else:
        print("{} {}".format(m, "No"))


def no16():
    """
    :return:
    """
    x = abs(int(input()))
    s = 0
    if x == 0:
        print(1)
        return
    while x:
        x //= 10
        s += 1
    print(s)


def no17():
    """
    :return:
    """
    n = int(input())
    s = 0
    for i in range(1, n + 1, 2):
        s += i * (i + 1)
    print(s)


def no18():
    """
    :return:
    """
    n = int(input())
    s = 0
    h = 100
    while n != 0:
        s += h
        h /= 2
        s += h
        n -= 1
    print("%.2f %.2f" % (s - h, h))


def no19():
    """
    :return:
    """
    n = int(input())
    s = 1
    l = 0
    count = 0
    m = 1
    while abs(s) >= pow(10, -n):
        if count % 2 == 0:
            s = 1 / m
        else:
            s = -1 / m
        m += 2
        l += s
        count += 1
    print("%.5f" % (4 * l))


def no20():
    """
    :return:
    """
    l = []
    s = 0
    n = int(input())
    for i in range(1, n + 1):
        l.append(i)
        s += 1 / sum(l)
    print('%.2f' % (s))


def no21():
    """
    :return:
    """
    s = input()
    str = input()
    print(s.count(str))


def no22():
    """
    :return:
    """
    s = input()
    l = list(s)
    for i in l:
        if s.count(i) == 1:
            print(i)
            return
    print(s, "error")


def no23_1(x):
    """
    :param x:
    :return:
    """
    for i in range(2, x, 1):
        if x % i == 0:
            return False
    return True


def no23():
    """
    :return:
    """
    num = int(input())
    for i in range(2, num // 2, 1):
        if no23_1(i) is True and no23_1(num - i) is True:
            print(i, num - i)


def no24():
    """
    :return:
    """
    s = input()
    for i in range(len(s) // 2):
        if s[i] != s[-(1 + i)]:
            print(s, "no")
            return
    print(s, "yes")


def no25():
    """
    :return:
    """
    inputs = input().split()
    x1, y1 = map(int, inputs[0].split('/'))
    x2, y2 = map(int, inputs[1].split('/'))
    a = Fraction(x1, y1)
    b = Fraction(x2, y2)
    print(a + b)


def no26():
    """
    :return:
    """
    s = input()
    l = []
    for i in s:
        if 'a' <= i <= 'z' or 'A' <= i <= 'Z':
            l.append(i.upper())
        else:
            l.append(i)
    print(''.join(l))


if __name__ == "__main__":
    no26()

函数部分练习题

# encoding: utf-8
# !/usr/bin/python
"""
@Filename:函数部分练习题
@Author: Jiaming
@Create date:2019/10/8
@Mail:[email protected]
@Blog:https://www.cnblogs.com/jiamingZ
@Description:
"""


def no1(year, month, day):
    """
    :param year:
    :param month:
    :param day:
    :return:
    """
    sum = 0
    month -= 1
    while month >= 1:
        if month == 1:
            sum += 31
        elif month == 2:
            if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
                sum += 29
            else:
                sum += 28
        elif month == 3:
            sum += 31
        elif month == 4:
            sum += 30
        elif month == 5:
            sum += 31
        elif month == 6:
            sum += 30
        elif month == 7:
            sum += 31
        elif month == 8:
            sum += 31
        elif month == 9:
            sum += 30
        elif month == 10:
            sum += 31
        elif month == 11:
            sum += 30
        elif month == 12:
            sum += 31
        month -= 1
    return sum + day


def no2(n, k):
    """
    :param n:
    :param k:
    :return:
    """
    sum = 0
    for i in range(1, n + 1, 1):
        sum += pow(i, k)
    return sum


def no3(n):
    """
    :param n:
    :return:
    """
    if n <= 2:
        return 1
    else:
        return no3(n - 1) + no3(n - 2)


def no4(x, y):
    """
    :param x:
    :param y:
    :return:
    """
    s = pow(x, 2) + pow(y, 2)
    if s < 4:
        return "in"
    elif s == 4:
        return "on"
    else:
        return "out"


def no5(x, y):
    """
    :param n:
    :return:
    """
    return x if y == 0 else no5(y, x % y)


sum = 0


def no6(n):
    """
    :param n:
    :return:
    """
    global sum
    sum += n % 10
    if n:
        no6(n // 10)


def no7(n):
    """
    :param n:
    :return:
    """
    if n == 0:
        return 1
    else:
        return 3 + no7(n - 1)


def no8(n):
    """
    :param n:
    :return:
    """
    sum = 0
    if n == 0:
        return sum
    for i in range(1, n):
        if n % i == 0:
            sum += i
    if sum == n:
        return "%d %s" % (n, 'yes')
    else:
        return "%d %s" % (n, 'no')


def no9(num):
    """
    :param n:
    :return:
    """
    n = len(str(num))
    if num < 0 or n == 1:
        return "%d wrong" % (num)
    s = str(num)[1:]
    return int(s)


def main():
    """
    :return:
    """
    # year, month, day = map(int, input().split())
    # print(no1(year, month, day))

    # n, k = map(int, input().split())
    # print(no2(n, k))

    # print(no3(int(input())))

    # x, y = map(float, input().split())
    # print("%.2f %.2f %s" %( x, y, no4(x, y)))

    # x, y = map(float, input().split())
    # print("%d" % (no5(x, y)))

    # n = int(input())
    # no6(abs(n))
    # print(sum)

    # n = int(input())
    # print(no7(n))

    # n = int(input())
    # print(no8(abs(n)))

    print(no9(int(input())))


main()

列表和元组部分练习题

# encoding: utf-8
# !/usr/bin/python
"""
@Filename:列表和元组部分练习题
@Author: Jiaming
@Create date:2019/10/8
@Mail:[email protected]
@Blog:https://www.cnblogs.com/jiamingZ
@Description:
"""


def no1():
    """
    :return:
    """
    x, y = map(int, input().split())
    l = []
    for i in range(x):
        templist = map(int, input().split())
        l.append(templist)
    x0 = y0 = 0
    xx = yy = 0
    max0 = -1
    for i in l:
        for j in i:
            if max0 < j:
                # print(j,x0,y0)
                # return
                max0 = j
                xx = x0
                yy = y0
            y0 += 1
        y0 = 0
        x0 += 1
    print(max0, xx, yy)


def no2():
    """
    :return:
    """
    l = list(map(int, input().split()))
    num = l[-1]
    l.pop(-1)
    low = 0
    high = len(l)
    mid = (low + high) // 2
    for i in range(len(l)):
        if mid >= len(l) or mid <= -1:
            print(num, 'no')
            return
        if l[mid] == num:
            print(mid)
            return
        elif l[mid] < num:
            low = mid + 1
        elif l[mid] >= num:
            high = mid - 1
        mid = (high + low) // 2
    print(num, 'no')


def no3():
    """
    :return:
    """
    num = int(input())
    tru = tuple((i for i in range(2, num + 1, 1)))
    l = list(tru)
    for i in range(len(tru)):
        for j in range(i + 1, len(tru)):
            if tru[j] % tru[i] == 0:
                if tru[j] in l:
                    l.remove(tru[j])
    k = 0
    for i in range(len(l)):
        print(l[k], end=' ')
        k += 1
        if k % 5 == 0:
            print()


def no4():
    """
    :return:
    """
    l = list(map(int, input().split()))
    s = []
    for i in l:
        if i % 3 != 0 and i % 5 != 0:
            s.append(i)
    if len(s) != 0:
        print(*s)
    else:
        print("NULL")


def no5():
    """
    :return:
    """
    x, y = map(int, input().split())
    l = []
    for i in range(x):
        tempList = list(map(int, input().split()))
        l.append(tempList)
    # print(l)
    s = []
    for i in range(y):
        for j in l:
            s.append(j[i])
    for k in range(0, len(s), 1):
        print(s[k], end=' ')
        if k % x != 0:
            print()


def no6():
    """
    :return:
    """
    l = list(map(int, input().split()))
    for i in range(len(l)):
        for j in range(len(l)):
            if l[i] < l[j]:
                l[i], l[j] = l[j], l[i]
    print(*l)


def no7():
    """
    :return:
    """
    N = int(input())
    l = list(map(int, input().split()))
    K = int(input())
    l.append(K)
    key = len(l) - 1
    for i in range(-1, -len(l) - 1, -1):
        if l[i] > K:
            l[i + 1] = l[i]
            key = i
    l[key] = K
    print(*l)


def no8():
    """
    :return:
    """
    l = list(map(float, input().split()))
    l.remove(min(l))
    l.remove(max(l))
    print("%.2f" % (sum(l) / len(l)))


def no9():
    """
    :return:
    """
    l = list(map(int, input().split()))
    for i in range(len(l)):
        min = i
        for j in range(i, len(l)):
            if l[j] < l[min]:
                min = j
        l[min], l[i] = l[i], l[min]
    print(*l)


def no10():
    """
    :return:
    """
    l1 = list(map(int, input().split()))
    l2 = list(map(int, input().split()))
    l3 = []
    for i in range(len(l1)):
        for j in range(len(l2)):
            if l2[j] in l1 and l2[j] not in l3:
                l3.append(l2[j])
    print(*l3)


def no11():
    """
    :return:
    """
    l = list(map(int, input().split()))
    max = min = 0
    for i in range(len(l)):
        if l[i] > l[max]:
            max = i
        elif l[i] < l[min]:
            min = i
    print(l[max], l[min])


def no12():
    """
    :return:
    """
    l = list(map(int, input().split()))
    a1 = a2 = a3 = a4 = a5 = 0
    for i in range(len(l)):
        if 90 <= l[i] <= 100:
            a1 += 1
        elif 80 <= l[i] < 90:
            a2 += 1
        elif 70 <= l[i] < 80:
            a3 += 1
        elif 60 <= l[i] < 70:
            a4 += 1
        else:
            a5 += 1
    print(a1, a2, a3, a4, a5)


def no13():
    """
    :return:
    """
    l = list(map(int, input().split()))
    num = l[-1]
    l.pop(-1)
    for i in range(len(l)):
        if l[i] == num:
            print(i)
            return
    print(num, "no")


def no14():
    """
    :return:
    """
    l = [1, 1]
    n = int(input())
    k = 0
    for i in range(0, n - 2):
        l.append(l[k] + l[k + 1])
        k += 1
    print(l[-1])


def no15():
    """
    :return:
    """
    l = list(map(int, input().split()))
    l.sort()
    print("%.2f" % (sum(l[2:-2]) / len(l[2:-2])))


def no16():
    """
    :return:
    """
    l1 = list(map(int, input().split()))
    l2 = list(map(int, input().split()))
    l3 = l1
    for i in l2:
        if i not in l1:
            l3.append(i)

    print(*l3)


def no17():
    """
    :return:
    """
    l = list(map(int, input().split()))
    l2 = list(set(l))
    l2.sort(key=l.index)
    print(*(l2))


if __name__ == "__main__":
    no17()

Python序列、字典和集合计分作业

def f(x):
    if x % 3 == 0:
        return False
    if x % 5 == 0:
        return False
    return True
def no1():
    l = list(map(int, input().split()))
    l = list(filter(f, l))
    if len(l) == 0:
        print('NULL')
    else:
        print(*l)

def no3():
    l1 = list(map(int, input().split()))
    l2 = sorted(l1)
    if l1 == l2:
        print("list",l1,"is already sorted")
    else:
        print("list {} is not sorted".format(l1))
def no8():
    """

    :return:
    """
    dictNumStr = {
        2: 'abc',
        3: 'def',
        4: 'ghi',
        5: 'jkl',
        6: 'mno',
        7: 'pqrs',
        8: 'tuv',
        9: 'wxyz',
    }
    s = input()
    s = s.lower()
    put = ''
    index = -1
    for i in s:
        if i in list(str(i) for i in range(10)) + ['-','*', '#', '+']:
            put += i
        else:
            index = -1
            for k, v in dictNumStr.items():
                if i in v:
                    put += str(k)
                    index = 1
            if index == -1:
                break
    if index == 1:
        print(put)
    else:
        print(s, 'invalid')
if __name__ == "__main__":
    main()


你可能感兴趣的:(Python)