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


x = [1000*(1+0.047)**i for i in range(1,11)]
res = sum(x)
print("{:.2f}".format(res))

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))
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值