【Python】第三章(容器)综合练习

【Python】第三章(容器)综合练习

scores = {"Zhang San": 45, "Li Si": 78, "Wang Wu": 40, \
         "Zhou Liu": 96, "Zhao Qi": 65, "Sun Ba": 90, \
         "Zheng Jiu": 78, "Wu Shi": 99, "Dong Shiyi": 60}
print(max(scores.values()))
print(min(scores.values()))
print(sum(scores.values())/len(scores))
print([k for k, v in scores.items() if v == max(scores.values())])

【Python】第三章(容器)综合练习

yr = int(input())
if (yr % 4 == 0 and yr % 100 != 0) or (yr % 400 == 0):
    print("闰年")
else:
    print("平年")

【Python】第三章(容器)综合练习

import random
x = [random.randint(1,100) for i in range(20)]
res = sorted(x[:10])+sorted(x[10:], reverse=True)
print(res)

【Python】第三章(容器)综合练习

import random
x = [random.randint(1, 100) for i in range(20)]
print(x)
x[::2] = sorted(x[::2], reverse=True)
print(x)

 【Python】第三章(容器)综合练习

s = input()
res = [(ch, s.index(ch)) for ch in s if s.count(ch) == 1]  # 带空格
res1 = [(ch, s.index(ch)) for ch in s if s.count(ch) == 1 and ch != ' ']  # 不带空格

for ch, index in res1:
    print(ch, " ", index)

 【Python】第三章(容器)综合练习

s = input()
res = [(ch, s.rfind(ch)) for ch in set(s)]
for ch, index in res:
    print(ch, " ", index)

【Python】第三章(容器)综合练习

from collections import Counter
s = input()
cnt = Counter(s).most_common()
for k, v in cnt:
    print(k, " ", v)

【Python】第三章(容器)综合练习

s = input()
if s == s[::-1]:
    print("Yes")
else:
    print("No")

【Python】第三章(容器)综合练习

import math
a = 10
b = 40
c = 15
det = b*b-4*a*c
if det > 0:
    res1 = (-b + math.sqrt(det)) / (2 * a)
    res2 = (-b - math.sqrt(det)) / (2 * a)
    print("{0:.2f} {1:.2f}".format(res1, res2))
elif det == 0:
    res = (-b) / (2 * a)
    print("{:.2f}".format(res))
else:
    print("无解")

【Python】第三章(容器)综合练习

total = 0
for yr in range(10):
    total = (total+1000)*(1+0.047)
print("{:.2f}".format(total))

【Python】第三章(容器)综合练习

from datetime import datetime
yr = datetime.now().year
mn = datetime.now().month
dy = datetime.now().day
print("{0:4d}-{1:2d}-{2:2d}".format(yr, mn, dy))

 

上一篇:某大学作业


下一篇:深入前端研发效能治理:数据化运营思路及其实践