编程语言
首页 > 编程语言> > 【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())])

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

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

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

 

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)

 

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

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

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

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("无解")

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

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))

 

标签:容器,ch,第三章,index,Python,res,scores,print,yr
来源: https://blog.csdn.net/fftx_00/article/details/122223345