1.编写程序, 编写一个学生类, 要求有一个计数器的属性, 统计总共实例化了多少个学生

class Student:
count=0
def __init__(self,name,age,gender):
self.name=name
self.age=age
self.gender=gender
Student.count+=1
ming=Student("小明",25,"male")
hong=Student("小红",25,"female")
lan=Student("小兰",25,"female")
print(Student.count)

2、人狗大战

class Person:
def __init__(self,name,aggr,hp,level):
self.name=name
self.aggr=aggr
self.hp=hp
self.level=level
def atta(self,dog):
dog.hp-=self.aggr
print("%s踢了一脚%s,%s掉了%s点血" % (self.name, dog.name, dog.name, self.aggr))
class Dog:
def __init__(self,name,aggr,hp,kind):
self.name=name
self.aggr=aggr
self.hp=hp
self.kind=kind
def bite(self,person):
person.hp-=self.aggr
print("%s咬了一口%s,%s掉了%s点血"%(self.name,person.name,person.name,self.aggr))
guo=Dog("果果",25,100,"金毛")
ming=Person("小明",25,100,15)
guo.bite(ming)
ming.atta(guo)
print(ming.__dict__)
print(guo.__dict__)

 3、正方形周长和面积

class Square:
def __init__(self,r):
self.side=r
def peri(self):
return "周长是%s"%(4*self.side)
def area(self):
return "面积是%s"%(self.side**self.side)
s=Square(2)
print(s.peri())
print(s.area())

python练习题-day22的更多相关文章

  1. Python练习题 028:求3*3矩阵对角线数字之和

    [Python练习题 028] 求一个3*3矩阵对角线元素之和 ----------------------------------------------------- 这题解倒是解出来了,但总觉得 ...

  2. Python练习题 027:对10个数字进行排序

    [Python练习题 027] 对10个数字进行排序 --------------------------------------------- 这题没什么好说的,用 str.split(' ') 获 ...

  3. Python练习题 026:求100以内的素数

    [Python练习题 026] 求100以内的素数. ------------------------------------------------- 奇怪,求解素数的题,之前不是做过了吗?难道是想 ...

  4. Python练习题 025:判断回文数

    [Python练习题 025] 一个5位数,判断它是不是回文数.即12321是回文数,个位与万位相同,十位与千位相同. ---------------------------------------- ...

  5. Python练习题 024:求位数及逆序打印

    [Python练习题 024] 给一个不多于5位的正整数,要求:一.求它是几位数,二.逆序打印出各位数字. ---------------------------------------------- ...

  6. Python练习题 004:判断某日期是该年的第几天

    [Python练习题 004]输入某年某月某日,判断这一天是这一年的第几天? ---------------------------------------------- 这题竟然写了 28 行代码! ...

  7. Python练习题-1.使用匿名函数对1~1000求和,代码力求简洁。

    Python 练习 标签(空格分隔): Python Python练习题 Python知识点 一.使用匿名函数对1~1000求和,代码力求简洁. 答案: In [1]: from functools ...

  8. PYTHON练习题 二. 使用random中的randint函数随机生成一个1~100之间的预设整数让用户键盘输入所猜的数。

    Python 练习 标签: Python Python练习题 Python知识点 二. 使用random中的randint函数随机生成一个1~100之间的预设整数让用户键盘输入所猜的数,如果大于预设的 ...

  9. python 基础 2.8 python练习题

    python 练习题:   #/usr/bin/python #coding=utf-8 #@Time   :2017/10/26 9:38 #@Auther :liuzhenchuan #@File ...

随机推荐

  1. 入坑C++

    c++中的++来自c语言中的递增运算符,该运算符将变量加1,c++起初也叫c with class ,通过通过名称表面,C++是对c的扩展,因此C++是c语言的超集,这以为这任何有效的c程序都是有效的 ...

  2. Mac 解决 Sourcetree 同步代码总需要密码的问题

    git config --global credential.helper osxkeychain

  3. kafka_2.11-2.1.0测试

    kafka测试启动创建topic ./kafka-topics.sh --create --zookeeper dip005:2181,dip006:2181,dip007 --replication ...

  4. 动态加载机Servlet容器加载器

    动态加载是Servlet 3.0中的新特性,它可以实现在 不重启Web应用的情况下加载新的Web对象(Servlet. Filter.Listener).Servlet容器加载器也是Servlet 3 ...

  5. Bootstrap-datepicker3官方文档中文翻译---概述(原文链接 http://bootstrap-datepicker.readthedocs.io/en/latest/index.html)

    bootstrap-datepicker Bootstrap-datepicker 提供了一个拥有Bootstrap样式的弹性Datepicker控件 Requirements/使用要求 Bootst ...

  6. Windows Internals 笔记——字符和字符串处理

    1.自Windows NT起,Windows的所有版本都完全用Unicode来构建,调用Windows函数时,如果向它传入一个ANSI字符串,那么函数首先会把字符串转换为Unicode,再把结果传给操 ...

  7. 解决微信小程序Video 某些属性设置不起作用问题

    <video controls="{{false}}" autoplay="{{true}}"></video> 设置属性务必要使用{{ ...

  8. CSS/Xpath 选择器 第几个子节点/父节点/兄弟节点

    0.参考 1.初始化 In [325]: from scrapy import Selector In [326]: text=""" ...: <div> ...

  9. 通用JDBC-demo

    1.JDBC 的工具包(utils):包含获取数据库连接, 关闭数据库资源等方法 JDBCTools_pro.java package com.app.utils; import java.beans ...

  10. [Error]Python虚拟环境报错 OSError: setuptools pip wheel failed with error code 2

    mkvirtualenv py35 python新建虚拟环境报错,setuptools pip wheel failed with error code 2 刚好昨天在CentOS安装的时候也总是报s ...