• 程序设计题-面向对象和面向过程#14718


    练习一:在终端输出如下信息‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬

      • 小明,10岁,男,上山去砍柴
      • 小明,10岁,男,开车去东北
      • 小明,10岁,男,最爱打游戏
      • 老李,90岁,男,上山去砍柴
      • 老李,90岁,男,开车去东北
      • 老李,90岁,男,最爱打游戏
      • def kanchai(name, age, gender):
        print "%s,%s岁,%s,上山去砍柴" %(name, age, gender)


        def qudongbei(name, age, gender):
        print "%s,%s岁,%s,开车去东北" %(name, age, gender)


        def dabaojian(name, age, gender):
        print "%s,%s岁,%s,最爱打游戏" %(name, age, gender)


        kanchai('小明', 10, '男')
        qudongbei('小明', 10, '男')
        dabaojian('小明', 10, '男')


        kanchai('老李', 90, '男')
        qudongbei('老李', 90, '男')
        dabaojian('老李', 90, '男')

        函数式编程

      • class Foo:

        def __init__(self, name, age ,gender):
        self.name = name
        self.age = age
        self.gender = gender

        def kanchai(self):
        print "%s,%s岁,%s,上山去砍柴" %(self.name, self.age, self.gender)

        def qudongbei(self):
        print "%s,%s岁,%s,开车去东北" %(self.name, self.age, self.gender)

        def dabaojian(self):
        print "%s,%s岁,%s,最爱打游戏" %(self.name, self.age, self.gender)


        xiaoming = Foo('小明', 10, '男')
        xiaoming.kanchai()
        xiaoming.qudongbei()
        xiaoming.dabaojian()

        laoli = Foo('老李', 90, '男')
        laoli.kanchai()
        laoli.qudongbei()
        laoli.dabaojian()

        面向对象

      • 2.
        class Xiaoming:
            role = '小明'
            def __init__(self,name,age,sex):
                self.name = name
                self.age = age
                self.sex = sex
            def work(self):
                hobby = ["上山去砍柴","开车去东北","最爱打游戏"]
                for i in hobby:
                    print(self.name,self.age,self.sex,i)
        class Laoli:
            role = '老李'
            def __init__(self, name, age, sex):
                self.name = name
                self.age = age
                self.sex = sex
            def work(self):
                hobby = ["上山去砍柴","开车去东北","最爱打游戏"]
                for i in hobby:
                    print(self.name,self.age,self.sex,i)
        a = Xiaoming('小明','10岁','男')
        b = Laoli('老李','90岁','男')
        a.work()
        b.work()
        class Men:
            def __init__(self,name,age,sex):
                self.name = name
                self.age = age
                self.sex = sex
            def hobby(self):
                hobby = ["上山去砍柴", "开车去东北", "最爱打游戏"]
                for i in hobby:
                    print(('%s,%s岁,%s,%s')%(self.name,self.age,self.sex,i))
        a = Men('小明',10,'男')
        b = Men('老李',90,'男')
        a.hobby()
        b.hobby()
  • 相关阅读:
    cookie的用法
    期货:高频日内交易
    开发者的福利 NutUIvscode 智能提示来了
    node_exporter/mysqld_exporter + Prometheus + Grafana 监控搭建
    reset.css
    移动端设备上的页面比例始终是1:1
    stylus
    移动端1px物理边框的css
    移动端解决click事件300毫秒延迟
    使 mysql datetime 精确到毫秒
  • 原文地址:https://www.cnblogs.com/567823a/p/12731177.html
Copyright © 2020-2023  润新知