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版本不对,导致不能安 ...
随机推荐
- 算法Sedgewick第四版-第1章基础-024-M/M/1 queue
/****************************************************************************** * Compilation: javac ...
- Python沙盒环境配置
一.简介 本文介绍配置python沙盒环境的方法步骤. 二.安装步骤 1.安装pyenv http://www.cnblogs.com/274914765qq/p/4948530.html 2.安装v ...
- 数据结构 nxd(顺序对)
数据结构 nxd(顺序对) 问题描述 给定 n 个数 a1,a2,...,an,求满足条件的(i,j)数量: i<j 且 a[i]<a[j] ★数据输入输入第一行为一个正整数 n.第二行为 ...
- [转]CentOS 7.3 安装MySQL
1.下载mysql源 yum -y install wget wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarc ...
- [转]Linux安装前配置操作记录
转至:http://m.blog.csdn.net/weixin_35884835/article/details/52385077 1.修改用户的SHELL的限制,修改/etc/security/l ...
- Dapper相关了解
公司新项目用的是Dapper,做的时候没有具体看dapper的具体用法,现在回来回顾总结一下. 1-总体介绍dapper 我们都知道ORM全称叫做Object Relationship Mapper, ...
- Vue v-if ToolList
可根据v-if="IsOk",动态判断标签是否展示 <template> <div id="app"> <input type=& ...
- 使用cydia substrate 来进行android native hook
cydia不仅可以hook java代码,同样可以hook native代码,下面举一个例子来进行android native hook 我是在网上找到的supermathhook这个项目,在他基 ...
- loj #2023. 「AHOI / HNOI2017」抛硬币
#2023. 「AHOI / HNOI2017」抛硬币 题目描述 小 A 和小 B 是一对好朋友,他们经常一起愉快的玩耍.最近小 B 沉迷于**师手游,天天刷本,根本无心搞学习.但是已经入坑了几个 ...
- 8、OpenCV Python 图像直方图
__author__ = "WSX" import cv2 as cv import numpy as np from matplotlib import pyplot as pl ...