
Python123题目参考答案__总结
这是我学习Python期间发现网上少有Python123答案,于是便将自己的所有解答分享出来。
二十四桥_
努力入世的后浪~~~
展开
-
更换披萨_
from math import *print(ceil((pi*(int(int(input())*2.54)/2)**2)/(pi*(int(int(input())*2.54)/2)**2)))原创 2022-01-08 18:20:42 · 854 阅读 · 0 评论 -
计算地球_
import mathfrom decimal import DecimalR = 6371000# 1. 计算地球表面积(表面积公式S = 4π(R**2))#=======================================================S=Decimal(4*math.pi*R**2).quantize(Decimal('0.01'),rounding='ROUND_HALF_UP')print(f'地球表面积为{S}平方米')#============.原创 2022-01-08 18:23:05 · 5349 阅读 · 1 评论 -
2019慈善排行
with open('2019Charity.csv', 'r', encoding='utf-8') as f: lis = [i.strip().split(',') for i in f.readlines()]pro = []for i in lis: if i[3] not in pro: pro.append(i[3])n = input()if n.lower() == 'total': num = sum([eval(i[5]) for .原创 2022-02-16 18:50:22 · 2404 阅读 · 0 评论 -
画sin函数
import numpy as npimport matplotlib.pyplot as pltx = np.linspace(0, 2 * np.pi, 200)y = np.sin(x)plt.plot(x, y, 'k')plt.show()原创 2022-02-16 18:49:30 · 1045 阅读 · 0 评论 -
利用numpy统计成绩
import numpy as npwith open('成绩单数字.csv', 'r', encoding='utf-8') as f: dic = {} for i in f.readlines(): i = i.strip().split(',') dic[i[0]] = [s for s in i[1:]]name_of_people, name_of_subject = input(), input()n = dic['姓名'].inde.原创 2022-02-16 18:48:52 · 4137 阅读 · 1 评论 -
商品房统计数据
with open('wuhan2021s1.csv', 'r', encoding='GBK') as f: lis = [] for i in f.readlines()[1:]: lis.append(i.strip().split(','))lis2 = ['江岸区', '江汉区', '硚口区', '汉阳区', '武昌区', '青山区', '洪山区', '东湖新技术开发区', '武汉经济开发区', '东西湖区', '蔡甸区', '江夏区', '黄陂区', '新洲.原创 2022-02-16 18:45:52 · 989 阅读 · 0 评论 -
JOSN转列表
import jsonwith open('score1034.json', 'r', encoding='utf-8') as f: ls1 = json.loads(f.read()) ls2 = [['姓名', '学号', 'C', 'C++', 'Java', 'Python', 'C#', '总分']] for i in ls1: ls2.append(list(i.values()))n = int(input())print(ls2[:n]).原创 2022-02-16 18:44:47 · 819 阅读 · 0 评论 -
替换数据中的敏感信息
with open('data.txt', 'r', encoding='utf-8') as f: for i in f.readlines(): if i[:4] == '身份证号': print(i[:11] + '*' * 8 + i[19:].strip()) elif i[:3] == '手机号': print(i[:7] + '*' * 4 + i[11:].strip()) else:.原创 2022-02-16 18:43:07 · 908 阅读 · 0 评论 -
Tiobe排行榜数据处理
data = open('成绩单.csv', 'r', encoding='utf-8')n = int(input())ls1 = []s = 0ls2 = []with open('成绩单.csv', 'r', encoding='utf-8') as f: for line in f.readlines(): line = line.strip('\n') ls = list(line.split(',')) ls1.append(l.原创 2022-02-16 18:42:27 · 755 阅读 · 0 评论 -
利用数据文件统计成绩
data = open('成绩单.csv', 'r', encoding='utf-8')n = int(input())ls1 = []s = 0ls2 = []with open('成绩单.csv', 'r', encoding='utf-8') as f: for line in f.readlines(): line = line.strip('\n') ls = list(line.split(',')) ls1.append(l.原创 2022-02-16 18:40:54 · 4194 阅读 · 1 评论 -
商品价格可视化
import numpy as npimport matplotlib.pyplot as pltplt.rcParams['font.sans-serif'] = ['SimHei']plt.rcParams['axes.unicode_minus'] = Falsewith open('rb2010.csv', 'r', encoding='utf-8') as f: file = f.readlines()[1:] date = [i.strip().split(',').原创 2022-02-13 18:13:46 · 555 阅读 · 0 评论 -
X射线衍射曲线绘制
import matplotlib.pyplot as pltdef read_file(file): """读数据到列表,映射为浮点数""" with open(file) as data: # 用上下文管理器打开文件,创建文件对象 data.readline() txt_to_list = [list(map(float, line.strip().split())) for line in data.readlines()] # 遍历文件 .原创 2022-02-09 21:43:01 · 1999 阅读 · 0 评论 -
商品价格统计查询
n = input()ls0 = []s = 0ls2 = []ls3 = []l = []c = 0dict1 = {'01': 0, '02': 0, '03': 0, '04': 0, '05': 0, '06': 0, '07': 0, '08': 0, '09': 0, '10': 0, '11': 0, '12': 0}with open('rb2010.csv', 'r', encoding='utf-8') as f: for line in f.readline.原创 2022-02-09 21:41:50 · 491 阅读 · 0 评论 -
酒店评论分析
import jieban = input()with open('comment.csv', 'r', encoding='GBK') as f: ls = [i.strip().split(',', maxsplit=1) for i in f.readlines()[1:]]c = 0d = 0count = 0ls1 = []ls2 = []dict1 = dict()dict2 = dict()ex = ['不错', '比较', '可以', '感觉', '没有',.原创 2022-02-09 21:40:54 · 598 阅读 · 0 评论 -
csv排序输出
n = int(input())ls1 = []with open('grade0.csv', 'r', encoding='utf-8') as f: for line in f.readlines(): line = line.strip('\n') ls = list(line.split(',')) ls1.append(ls)ls1.sort(key=lambda x: (x[n - 1], x[0]))for i in ls1:.原创 2022-02-09 21:38:58 · 1488 阅读 · 0 评论 -
通讯录读取
n = input()dict1 = dict()with open('info.csv', 'r', encoding='GBK') as f: for line in f.readlines(): line = line.strip('\n') ls = list(line.split(',')) ls1 = ls[1:] dict1[ls[0]] = ls1if n == 'A': with open('info.原创 2022-02-09 21:38:11 · 1277 阅读 · 0 评论 -
2019体育数据收入
with open('2019sport.csv', 'r', encoding='utf-8') as data: ls1 = [] while True: tentative = data.readline().strip().split(',') if '' in tentative: break else: ls1.append(tentative) # prin.原创 2022-02-09 21:37:05 · 649 阅读 · 0 评论 -
词频统计python
def read_file(file): """接收文件名为参数,将文件中的内容读为字符串, 只保留文件中的英文字母和西文符号, 过滤掉中文(中文字符及全角符号Unicode编码都大于256) 将所有字符转为小写, 将其中所有标点、符号替换为空格,返回字符串 """ with open(file, 'r', encoding='utf-8') as data: string_sign = '!"\'-#$%&()*+,./:;.原创 2022-02-09 21:35:55 · 3353 阅读 · 6 评论 -
大学排行榜
def read_file(file, m): """读文件中的学校名到列表中,返回排名前m学校集合""" ls = [] if file == './alumni.txt': with open(file, 'r', encoding='utf-8') as data: for line in data.readlines(): ls.append(line.strip().split(' ')[2]) .原创 2022-02-09 21:34:07 · 1429 阅读 · 2 评论 -
体育收入排行2012-2019(用列表)
def read_file(): with open('2012-19sport.csv', 'r', encoding='utf-8') as data: # ls1 = data.readline().strip().split(',') data.readline() ls2 = [] for line in data.readlines(): ls2.append(line.strip().split(.原创 2022-02-02 21:47:03 · 4792 阅读 · 0 评论 -
体育收入排行2012-2019(用pandas)
import pandas as pdimport numpy as npdef fun1(n): k = int(input()) data = pd.read_csv('2012-19sport.csv', index_col=0) data_tentative = data.loc[data['Year'] == n] # data_tentative = data_tentative.set_index('Name') data_tentative =.原创 2022-02-02 21:47:12 · 1659 阅读 · 0 评论 -
文件中数据转列表
with open('xrdfile.txt', 'r', encoding='utf-8') as data: ls1 = [] while True: tentative = data.readline() if tentative: line_to_ls = list(map(float, tentative.strip().split(' '))) # print(line_to_ls) .原创 2022-02-02 21:47:20 · 604 阅读 · 0 评论 -
读取附件中的内容
with open('fruit.txt', 'r', encoding='utf-8') as data: print(data.read())原创 2022-02-02 21:47:28 · 880 阅读 · 0 评论 -
统计文件中的中文文字数
def count_character(name): with open(name, 'r', encoding='utf-8') as data: string_get = data.read().strip() check_string = ",。?!@#¥%……&*;(:; ) ——+|、·:“”’‘\n" for i in check_string: if i in string_get: string_get.原创 2022-02-01 21:22:40 · 535 阅读 · 0 评论 -
判断完数python
n = 10000for x in range(2, n + 1): s = x lt = [] for i in range(1, x): if x % i == 0: s -= i lt.append(i) if s == 0: print("完数∶{},因子包括:".format(x), end="") for j in range(0, len(lt)): .原创 2022-02-01 21:21:43 · 1541 阅读 · 0 评论 -
分配学号python
with open('studentList.csv', mode='r', encoding='utf-8') as stuData: lsStu = [line.strip().split(',') for line in stuData]with open('schoolCode.csv', mode='r', encoding='utf-8') as schData: lsSch = [line.strip().split(',') for line in schData] .原创 2022-02-01 21:19:00 · 2287 阅读 · 1 评论 -
地区查询python
def file_to_dict(area_file): """接收一个表示文件名的字符串为参数,将文件中的数据保存到字典中,返回字典。""" area_in_dict = {} with open(area_file, 'r', encoding='utf-8') as data: # 读文件 for x in data: # 遍历文件对象 ls = x.strip().split(',') .原创 2022-02-01 21:18:05 · 2643 阅读 · 0 评论 -
县区查询python
# (1)如果用户输入的是地级市名,以列表形式输出其下辖所有下辖区、县和# 县级市名称。# (2)如果用户输入的是市辖区、县或县级市名,则输出其上一级的地级市# 名,若有的市辖区名在不同地级市中同时存在时,分行输出全部地级市名。# 方法一with open('hebei.txt', 'r', encoding='utf-8') as name: hebei_lst = [x.strip().split(',') for x in name]# print(hebei_lst ) .原创 2022-02-01 21:17:22 · 2594 阅读 · 0 评论 -
查询高校名
def read_csv_to_lst(filename): """接收CSV文件名为参数,读取文件内容到二维列表,每行数据根据逗号切分为子列表,返回二维列表。""" with open(filename, 'r', encoding='utf-8') as f: university_lst = [line.strip().split(',') for line in f] return university_lstdef query_name(word, .原创 2022-02-01 21:15:29 · 2163 阅读 · 0 评论 -
查询高校信息
with open('university.csv', 'r', encoding='utf-8') as Uname: ls = Uname.readlines()# print(ls)name = input()for line in ls: if name in line: print(ls[0].strip()) print(line.strip())原创 2022-02-01 21:14:47 · 2230 阅读 · 0 评论 -
统计文章字符数
def readFile(filename, num): with open(filename, 'r', encoding='utf-8') as file: # 只读模式打开文件 content = file.readlines() # 文件全部内容读取出来放入列表中,每个元素为一行字符串 txt = ''.join(content[:num]) # 列表的前num行连接为字符串 return len(txt), len(set(txt)) # 以元组形.原创 2022-02-01 21:13:56 · 2319 阅读 · 0 评论 -
身份证号批量排序
def id15218(id15): ls = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2] ecc = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'] sum = 0 j = 0 if int(id15[6:8]) >= 5: id17 = id15[0:6] + '19' + id15[6:] else: .原创 2022-01-23 12:08:01 · 537 阅读 · 0 评论 -
统计文本中单词数
def readFile(filename): with open(filename, 'r') as file: # 只读模式打开文件 content = file.read() # 文件内容读入到一个字符串 return content # 返回字符串def replaceTxt(txt): for ch in '!"#$%&()*+,./:;<=>?@[\\]^_‘{|}~\n': txt = txt.repla.原创 2022-01-23 12:07:13 · 647 阅读 · 0 评论 -
统计字母数量
s = 'abcdefghijklmnopqrstuvwxyz'n = int(input())with open('The Old Man and the Sea.txt', 'r', encoding='utf-8') as data: txt = data.readlines()if n > len(txt): n = len(txt)mystr = ' '.join(txt[:n])# print(mystr)ls = [[x, mystr.lower().cou.原创 2022-01-23 12:06:18 · 1182 阅读 · 0 评论 -
汉英词典python
import stringdef read_to_dic(filename): """读文件每行根据空格切分一次,作为字典的键和值添加到字典中。 返回一个字典类型。 """ my_dic = {} with open(filename, 'r', encoding='utf-8') as data: for x in data: x = x.strip().split(maxsplit=1) my.原创 2022-01-23 12:05:33 · 1849 阅读 · 0 评论 -
使用字典来统计词频
freqDict = eval(input())for word in input().split(): freqDict[word] = freqDict.get(word, 0) + 1print(freqDict)原创 2022-01-23 12:03:29 · 834 阅读 · 0 评论 -
字典属性、方法和应用
def method_of_dict(n, my_dict): for i in range(n): ls = input().split() # 输入命令及参数,之间用空格分隔 if ls[0] == 'print': # 每遇到“print”时,在新的一行输出字典 print(my_dict) elif ls[0] == 'key': # 如果输入的命令是“key”,输出字典中全部键 prin.原创 2022-01-23 12:01:32 · 2541 阅读 · 0 评论 -
查询省会python
capitals = {'湖南':'长沙','湖北':'武汉','广东':'广州','广西':'南宁','河北':'石家庄','河南':'郑州','山东':'济南','山西':'太原','江苏':'南京','浙江':'杭州','江西':'南昌','黑龙江':'哈尔滨','新疆':'乌鲁木齐','云南':'昆明','贵州':'贵阳','福建':'福州','吉林':'长春','安徽':'合肥','四川':'成都','西藏':'拉萨','宁夏':'银川','辽宁':'沈阳','青海':'西宁','甘肃':'.原创 2022-01-23 12:00:41 · 5144 阅读 · 0 评论 -
字典增加元素
dict1 = {'赵广辉': '13299887777', '特朗普': '814666888', '普京': '522888666', '吴京': '13999887777'}# 查询键是否存在,存在时返回键值对,不存在返回"数据不存在"newName = input()newValue = input()if (newName in dict1): print("您输入的姓名在通讯录中已存在")else: dict1[newName] = newValue for.原创 2022-01-21 20:07:37 · 717 阅读 · 0 评论 -
通讯录(MOD)
def menu(): print('''\n欢迎使用PYTHON学生通讯录1:添加学生2:删除学生3:修改学生信息4:搜索学生5: 显示全部学生信息6:退出并保存''')dic = {'张自强': ['12652141777', '材料'], '庚同硕': ['14388240417', '自动化'], '王岩': ['11277291473', '文法']}print(dic)menu()c = input()if c == '3': name = inpu.原创 2022-01-20 20:24:06 · 1654 阅读 · 0 评论