python3 练习3
##c##写法
#include<iostream>
using namespace std;
class Rectangle{
public:
int j;
void area(int X=0,int Y=0,int A=0,int B=0);
private:
int x,y,a,b;
};
void Rectangle::area(int X,int Y,int A,int B){
x=X;y=Y;a=A;b=B;
j=(a-x)*(b-y);
}
int main(){
int x,y,a,b;
Rectangle rectangle;
cout<<"输入左下角坐标x和y"<<endl;
cin>>x>>y;
cout<<"输入右上角坐标为a和b"<<endl;
cin>>a>>b;
rectangle.area(x,y,a,b);
cout<<"该矩形面积为:"<<rectangle.j<<endl;
return 0;
}
## 1 编写一个rectangle 类,属性为左上角和右下角的坐标,编写方法,计算矩形面积
class Rectangle:
def __init__(self,x1=0,y1=0,x2=1,y2=1):
self.x1=x1
self.y1=y1
self.x2=x2
self.y2=y2
def print_area(self,t):
print((t.x2-t.x1)*(t.y2-t.y1))
t=Rectangle()
t.x1=1.0
t.x2=2.1
t.y1=2.0
t.y2=3.2
t.print_area(t) #### 编写一个stu 类,属性包括学号,和三门成绩,编写方法,输出平均成绩,并输出是否通过。
class stud:
stuid=''
score1=''
score2=''
score3=''
def setstuid(self,stuid):
self.stuid=stuid
def setscore1(self,score1):
self.score1=score1
def setscore2(self,score2):
self.score2=score2
def setscore3(self,score3):
self.score3=score3
def getstuid(self,stuid):
return self.stuid
def getscore1(self,score1):
return self.score1
def getscore2(self,score2):
return self.score2
def getscore3(self,score3):
return self.score3 def addstudent():
stu=stud()
stuid=input('请输入学号id:')
stu.setstuid(stuid)
score1 = input('请输入成绩一:')
stu.setscore1(score1)
score2 = input('请输入成绩二:')
stu.setscore2(score2)
score3 = input('请输入成绩三:')
stu.setscore3(score3)
avg=(int(stu.score1)+int(stu.score2)+ int(stu.score3))/3
print(avg) if int(stu.score1) < 60:
print('failed')
elif int(stu.score2) < 60:
print('failed')
elif int(stu.score3) < 60:
print('failed')
else:
print('passwd') addstudent()
python3 练习3的更多相关文章
- python3 threading初体验
python3中thread模块已被废弃,不能在使用thread模块,为了兼容性,python3将thread命名为_thread.python3中我们可以使用threading进行代替. threa ...
- Python3中的字符串函数学习总结
这篇文章主要介绍了Python3中的字符串函数学习总结,本文讲解了格式化类方法.查找 & 替换类方法.拆分 & 组合类方法等内容,需要的朋友可以参考下. Sequence Types ...
- Mac-OSX的Python3.5虚拟环境下安装Opencv
Mac-OSX的Python3.5虚拟环境下安装Opencv 1 关键词 关键词:Mac,OSX,Python3.5,Virtualenv,Opencv 2 概述 本文是一篇 环境搭建 的基础 ...
- Ubuntu部署python3.5的开发和运行环境
Ubuntu部署python3.5的开发和运行环境 1 概述 由于最近项目全部由python2.x转向 python3.x(使用目前最新的 python3.5.1) ,之前的云主机的的默认python ...
- Python3 登陆网页并保持cookie
网页登陆 网页登陆的原理都是,保持一个sessionid在cookie然后,根据sessionid在服务端找到cookie进行用户识别 python实现 由于python的简单以及丰富的类库是开发网络 ...
- 阿里云 SDK python3支持
最近的一个项目需要操作阿里云的RDS,项目使用python3,让人惊讶的是官方的SDK竟然只支持python2 在阿里云现有SDK上改了改,文件的修改只涉及aliyun/api/base.py,详见h ...
- python3爬取1024图片
这两年python特别火,火到博客园现在也是隔三差五的出现一些python的文章.各种开源软件.各种爬虫算法纷纷开路,作为互联网行业的IT狗自然看的我也是心痒痒,于是趁着这个雾霾横行的周末瞅了两眼,作 ...
- CentOS7中安装Python3.5
1.下载 https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz 2.上传到服务器 3. 安装相关依赖 yum install gcc ope ...
- 使用virtualenv搭建python3开发环境
问题描述 环境: CentOS6.5 想在此环境下使用python3进行开发,但CentOS6.5默认的python环境是2.6.6版本. 之前的做法是直接从源码安装python3,替换掉现有的开发环 ...
- 烂泥:python2.7和python3.5源码安装
本文由ilanniweb提供友情赞助,首发于烂泥行天下 想要获得更多的文章,可以关注我的微信ilanniweb 前几天在centos6.6安装ansible时,一直提示python版本不对,导致不能安 ...
随机推荐
- GCD 学习(三)Main&Global Dispatch Queue
摘录自:http://zhuyanfeng.com/archives/3066 Main Dispatch Queue是在主线程中执行任务的Dispatch Queue.因为主线程只有1个,所以Mai ...
- ZROI2018普转提day1t4
传送门 分析 就是飞飞侠这道题...... 我们可以将这张图建成好几层,每一层可以向下一层的上下左右无代价移动,而对于每个点如果付b[i][j]的代价就可以走到比它高a[i][j]的层上.我们用这种方 ...
- Inheritance with EF Code First: Part 2 – Table per Type (TPT)
In the previous blog post you saw that there are three different approaches to representing an inher ...
- 《Effective Java》第11章 序列化
"将一个对象编码成一个字节流",称作将该对象序列化(serializing); 相反的处理过程被称作反序列化(deserializing),一旦对象被序列化后,它的编码就可以从一台 ...
- 自己封装一个MySignal函数,方便以后直接copy.
传统的signal可能会有信号未决或者信号重入或多或少的问题,毕竟这个函数已经很多年了. 所以推荐使用sigaction函数,但是sigaction函数相对signal较为复杂,而且每次要写一大堆.因 ...
- git命令(二)
2.查看.添加.提交.删除.找回,重置修改文件 3.查看文件diff git diff <file> # 比较当前文件和暂存区文件差异 git diff git diff <$id1 ...
- MVC异常的统一处理
禁用异常跟踪 很多时候异常是不可预料的,在每个Action方法或Controller上应用Exception Filter是不现实的.而且如果异常出现在View中也无法应用Filter.如RangeE ...
- Unity中Awake的执行时间点
https://docs.unity3d.com/ScriptReference/MonoBehaviour.Awake.html 根据官方文档,Awake的实际执行点,应该是对应mono脚本所在物体 ...
- 【C#】记录程序耗时方法
最近写了一个读txt题库然后导入数据库的控制台应用,查看存入数据库耗时 在C#中使用 Stopwatch 命名空间: System.Diagnostics: 使用方法: System.Diagn ...
- 泛型List<T>转存为XML文档
经常会有这情况,在程序处理结果为泛型List<T>,但为了能把这些集合输出XML文档.Insus.NET就因此问题,演示一个范例.在程序中,创建一个类: List<T>的集合手 ...