栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

本周学习内容20211115

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

本周学习内容20211115

一、python 面向对象编程 

1. 目录

 2. 类

class Person:
    def __init__(self,name,age):
        self.name = name
        self.age = age
    def display(self):
        print("person(姓名:{},年龄:{})".format(self.name,self.age))
        
p1=Person("李白",28)
p1.name
p1.display()

p2=Person("张三",30)
print(p2.name)
print(p2.age)
p2.display()

'''
In [5]: p1.name
Out[5]: '李白'
'''

'''
person(姓名:李白,年龄:28)
张三
30
person(姓名:张三,年龄:30)
'''

 3. 类属性

class Person:
    pernum = 0  #类属性
    def __init__(self,name,age):
        self.name = name
        self.age = age
        Person.pernum+=1
    def display(self):
        print("person(姓名:{},年龄:{})".format(self.name,self.age))
    def display_pernum(self):
        print(Person.pernum)
        
        
p3=Person("zs",32)
print(p3.pernum)
p3.display_pernum()

p4=Person("qwe", 42)
print(Person.pernum)
print(p4.pernum)
p4.display_pernum()

'''
1
1
2
2
2
'''

4. 继承

class Person:
    pernum = 0  #类属性
    def __init__(self,name,age):
        self.name = name
        self.age = age
        Person.pernum+=1
    def display(self):
        print("person(姓名:{},年龄:{})".format(self.name,self.age))
    def display_pernum(self):
        print(Person.pernum)
               
class Student(Person):  #继承
    def __init__(self,name,age,university):
        super(Student,self).__init__(name,age)
        self.university = university
    def display(self):
        print("Student(姓名:{},年龄:{},大学:{})".format(self.name,self.age,self.university))

s1=Student("jd", 23, "bjdx")
print(s1.university)
s1.display() #重写
s1.display_pernum()  #继承

5. 标准库

 

 

二、c语言学习

 

#include 
int main(){
	int n;
	char a='A';
	scanf("%d",&n); 
	for(int i=0;i<=n;i++){
		for(int j=n-i;j>0;j--){
			printf("%c ",a++);
		}
		printf("n");
	}
	
	
	
	return 0;
}

 

#include 
int main(){
	int n,a[100],i=0;
	scanf("%d",&n);
	do{
		a[i]=n%10;
		n=n/10;
		i++;
	}while(n!=0);
	for(int j=i-1;j>=0;j--){
		printf("%d ",a[j]);
	}
	return 0;
}

 

#include 
int main(){
	long int a,n;
	scanf("%ld %ld",&a,&n);
	double s=a,h=a;
	for(int i=1;i<=n;i++){
		s+=h;
		h=h/2;
	}
	s-=2*h;
	if(n==0){
		printf("0.0 0.0");	
	}else
		printf("%.1f %.1f",s,h);
	return 0;
}

#include 
#include 
int ss(int x){
	if(x==1) return 0;
	if(x==2) return 1;
	for(int a=2;a<=sqrt(x)+1;a++){
		if(x%a==0) return 0;
	}
	return 1;
}

int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		if(ss(i)&&ss(n-i)) {
			printf("%d = %d + %d",n,i,n-i);
			break;
		}
	}
	return 0;
}

 

#include 
#include 
int main(){
	int n,a[8];
	scanf("%d",&n);
	for(int i=pow(10,n-1);i 

 

 

#include 
int main(){
	int n,min,x;
	scanf("%d",&n);
	scanf("%d",&x);
	min=x;
	for(int i=0;i 

#include 
#include 
int ss(int a){
	if(a==1)
		return 0;
	else if(a==2)
		return 1;
	for(int i=2;i 

 

 

#include 
#include 

int main(){
	double n,sum=0,temp;
	int flag=1,fm=1;
	scanf("%lf",&n);
	do{
		temp=flag*(1/(double)fm);
		sum+=temp;
		flag=-flag;
		fm+=3;
	}while(fabs(temp)>n);
	printf("sum = %.6f",sum);
} 

 

#include 
#include 
double jc(int a){
	double s = 1;
	for(int i=1;i<=a;i++){
		s = s * i;
	}
	return s;
}

int main(){
	double n,sum=1,last=1;
	scanf("%lf",&n);
	for(int i=1;;i++){
		last=pow(n,i)/jc(i);
		sum+=last;
		if(fabs(last)<0.00001) break;
	}
	printf("%.4f",sum);
}

#include 
#include 
int ss(int a){
	if(a==1)
		return 0;
	else if(a==2)
		return 1;
	for(int i=2;i 

 

#include 
#include 

int main(){
	int m,n,flag=1;
	scanf("%d %d",&m,&n);
	for(int i=m;i<=n;i++){
		int sum=0,k=0;
		int a[100];
		for(int j=1;j 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/529458.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号