Write a definition for a class named Kangaroo with the following methods:

  • An __init__ method that initializes an attribute named pouch_contents to an empty list
  • A method named put_in_pouch that takes an object of any type and adds it to pouch_contents.
  1. class Kangaroo:
  2. """ attributes: pouch_contents"""
  3.  
  4. def __init__(self):
  5. self.pouch_contents = list()
  6.  
  7. def __str__(self):
  8. temp = ''
  9. for s in self.pouch_contents:
  10. temp+=str(s)+ '\n'
  11. return temp
  12.  
  13. def put_in_pouch(self,obj):
  14. self.pouch_contents.append(obj)
  15.  
  16. k = Kangaroo()
  17. k.put_in_pouch(1)
  18. k.put_in_pouch(1.0)
  19. k.put_in_pouch('hello sun')
  20. k.put_in_pouch((1,2,3))
  21.  
  22. k1 = Kangaroo()
  23. k1.put_in_pouch([1,2,3])
  24. k1.put_in_pouch({'':'sun','':'yu'})
  25. k1.put_in_pouch('this is k1')

from Thinking in Python

Exercises - Kangaroo的更多相关文章

  1. [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]Contents

    I find it may cost me so much time in doing such solutions to exercises and problems....I am sorry t ...

  2. 6656 Watching the Kangaroo

    6656 Watching the KangarooDay by day number of Kangaroos is decreasing just liketiger, whale or lion ...

  3. 46 Simple Python Exercises (前20道题)

    46 Simple Python Exercises This is version 0.45 of a collection of simple Python exercises construct ...

  4. Gym 101981K - Kangaroo Puzzle - [玄学][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem K]

    题目链接:http://codeforces.com/gym/101981/problem/K Your friend has made a computer video game called “K ...

  5. State Estimation for Robotics (Tim Barfoot) exercises Answers

    Here are some exercises answers for State Estimation for Robotics, which I did in June, 2017. The bo ...

  6. Linux command line exercises for NGS data processing

    by Umer Zeeshan Ijaz The purpose of this tutorial is to introduce students to the frequently used to ...

  7. 100 numpy exercises

    100 numpy exercises A joint effort of the numpy community The goal is both to offer a quick referenc ...

  8. 46 Simple Python Exercises-Very simple exercises

    46 Simple Python Exercises-Very simple exercises 4.Write a function that takes a character (i.e. a s ...

  9. E - Cheap Kangaroo(求多个数的最大公约数)

    Description There are N kangaroos going out to eat at an Indian restaurant. The ith kangaroo wants t ...

随机推荐

  1. win8以管理员身份安装软件

    win8以管理员身份安装软件 msiexec /package

  2. Linux下nice/renice命令小结

    1. nice命令 内核根据进程的nice值决定进程需要多少处理器时间. nice值的取值范围是是: -20到20. 一个具有-20 的 nice 值的进程有很高的优先级. 一个 nice 值为 20 ...

  3. 无法找到类:java.lang.ClassNotFoundException: com.tt.javaweb.HttpServletRequest问题解决

    问题如下:找不到Httpservlet对应的Class,进入build目录下发现确实没有对应的class文件. 严重: Allocate exception for HttpServletReques ...

  4. java工程师分享:我是如何自学成才的?

    原文:http://www.java800.com/peixun-79062115.html 我是10年河南工业大学的毕业生,当时我们专业许多学生都去报了java培训机构,去达内的都不少.我也想去培训 ...

  5. “代理 XP”组件已作为此服务器安全配置的一部分被关闭。解决方法

    新建维护计划的时候遇到下图的报错信息 标题: Microsoft SQL Server Management Studio------------------------------ “代理 XP”组 ...

  6. Hadoop学习4--安装Hadoop

    首先献上Hadoop下载地址: http://apache.fayea.com/hadoop/core/ 选择相应版本,点一下,直接进行http下载了. 对原来写的一篇文章,相当不满意,过于粗糙了,于 ...

  7. ThreadPoolExecutor使用介绍

    private static ExecutorService exec = new ThreadPoolExecutor(8, 8, 0L,TimeUnit.MILLISECONDS, new Lin ...

  8. OAF_架构MVC系列1 - MVC的概述(概念)

     2015-04-03 Created By BaoXinjian

  9. NeHe OpenGL教程 第十八课:二次几何体

    转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...

  10. 基于redis的分布式锁

    <?php /** * 基于redis的分布式锁 * * 参考开源代码: * http://nleach.com/post/31299575840/redis-mutex-in-php * * ...