随笔分类 - python习题
Pandas应用实例(DataFrame基本操作,画图)
摘要:题目要求 利用Pandas建立学生信息二维表,包含姓名、年龄、性别、专业、个人电子设备数量和平均月支出(以一百元为单位)六类信息,至少创建10条具有代表性的记录(10分)。 显示最后三行的信息并筛选出个人电子设备超过3的学生(10分)。 利用Matplotlab绘制反映月支出和电子设备数量关系的散点
7-8 sdut-统计工龄- 字典排序
摘要:使用sorted函数 n=int(input()) num=[int(x) for x in input().split()] mp={} for i in num: mp.setdefault(i,0) mp[i]=mp[i]+1 for i,j in sorted(mp.items()): pr
7-3 sdut-判断回文字符串
摘要:知识点 正则表达式 代码1 使用sub import re str=input() # 转化为小写 str=str.lower() # 只保留数字和字母 str=re.sub('[^0-9a-z]',"",str) # 逆转字符串 str1=str[::-1] if str==str1: print
7-4 sdut-oop-1 简单的复数运算
摘要:点击查看题目 设计一个类Complex,用于封装对复数的下列操作: 成员变量:实部real,虚部image,均为整数变量; 构造方法:无参构造方法、有参构造方法(参数2个) 成员方法:含两个复数的加、减、乘操作。 复数相加举例: (1+2i)+(3+4i)= 4 + 6i 复数相减举例: (1+2i
8-4 文件编程7-4
摘要:知识点 按行取数据 代码: f=open("F:\\vsnode\\python\\water.txt","r+",encoding='utf-8') while True: line=f.readline() if not line :break line_list=list(line.split
8-3 文件编程7-3 sdut-python
摘要:知识点 按对应的编码方式打开文件 处理list中有不同数据如果转化为字符串 代码 import re f=open("F:\\vsnode\\python\\freedom.txt","r+",encoding='utf-8') strs=f.read() # print(strs) f.close
8-1 文件编程7-1 - python文件基础
摘要:记得更换文件地址 f=open("F:\\vsnode\\python\\example.txt","r+") str=f.read() f.close() ans=[] for i in str: if i.isupper(): ans.append(i.lower()) if i.islower
7-7 sdut-oop-7 答答租车系统(类的继承与多态 面向对象综合练习)- -python
摘要:写了很多冗余数据:车型名称可以不要 class Che: id=0 name='A' maxpeo=0 weight=0 meo=0 def __init__(self,id,name,maxpeo,weight,meo): self.id=id self.name=name self.maxpeo
7-6 sdut-oop-9 计算长方形的周长和面积(类和对象) --python
摘要:知识点: python创建多个构造方法 使用classmethod 将init的参数设为可变类型,在init语句中判断 class Rect: __length = 0 __width = 0 def __init__(self, l, w): self.__length = l self.__wi
7-5 sdut-oop-6 计算各种图形的周长(多态)-- python
摘要:from abc import ABCMeta, abstractmethod import math from webbrowser import BaseBrowser class Shape: __metaclass__=ABCMeta @abstractmethod def length(s
7-4 sdut-oop-5 计算长方体和四棱锥的表面积和体积(类的继承) python
摘要:Python __ 面向对象基础 import math as m class Rect: l = 0.0 h = 0.0 z = 0.0 def __init__(self, l, h, z): self.l = l self.h = h self.z = z def length(self):
7-2 sdut-Time类的定义与使用
摘要:from cgi import print_arguments class Time: __hour=0 __minute=0 __second=0 #设置数据成员hour的值(采用12小时制),非法的输入默认为12; def setHour(self, h): if h>12 or h<0: se
7-1 sdut-oop-2 Shift Dot(类和对象)python
摘要:class Point: x=0 y=0 def __init__(self,xx,yy): self.x=xx self.y=yy def move(self,x1,y1): self.x+=x1 self.y+=y1 def toString(self): return "({},{})".fo
7-3 sdut-分数加减法
摘要:from fractions import Fraction as F while True: try: a = input() if a.find('+')!=-1: ls = a.split('+') print(F(ls[0]) + F(ls[1])) elif a.find('-')!=-1
7-2 sdut-oop-8 分数四则运算(类和对象) -- Fraction的使用
摘要:from fractions import Fraction as F n=int(input()) for i in range(n): a = input() if a.find('+')!=-1: ls = a.split('+') print(F(ls[0]) + F(ls[1])) eli
7-1 sdut-分数的化简 -- Fraction的使用
摘要:#做法1: 使用内置函数Fraction from fractions import Fraction while True: try: a,b=map(int,input().split("/")) print(Fraction(a,b)) except: break 做法2:手写gcd **知识
7-2 sdut-列表元素个数的加权和(1)
摘要:递归 def sum(n,deep): sums = 0 # print(deep) for i in n: if isinstance(i, list): sums += sum(i,deep+1) if isinstance(i, int): sums += deep return sums a
7-1 sdut-求全排列 -- 内置全排列函数
摘要:from itertools import permutations n=int(input()) for i in permutations(list( range(1,n+1) )): print("".join(map(str,i)))
7-12 sdut-集合相等问题 - -扩展
摘要:扩展: 蒙特卡罗算法: 蒙特卡罗方法(英语:Monte Carlo method),也称统计模拟方法,是1940年代中期由于科学技术的发展和电子计算机的发明,而提出的一种以概率统计理论为指导的数值计算方法。是指使用随机数(或更常见的伪随机数)来解决很多计算问题的方法。 解释: 假设我们要计算一个不规
7-10 sdut-两数之和
摘要:原文 知识点: 这个else用的很灵性,学习到了 list的index的使用 l=[int(x) for x in input().split()] num=int(input()) d={} for i in l: d[i]=num-i for key,value in d.items(): if