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

2021/12/29 22:08:37

本文主要是介绍【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))

 



这篇关于【Python】第三章(容器)综合练习的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程