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.
class Kangaroo:
""" attributes: pouch_contents""" def __init__(self):
self.pouch_contents = list() def __str__(self):
temp = ''
for s in self.pouch_contents:
temp+=str(s)+ '\n'
return temp def put_in_pouch(self,obj):
self.pouch_contents.append(obj) k = Kangaroo()
k.put_in_pouch(1)
k.put_in_pouch(1.0)
k.put_in_pouch('hello sun')
k.put_in_pouch((1,2,3)) k1 = Kangaroo()
k1.put_in_pouch([1,2,3])
k1.put_in_pouch({'':'sun','':'yu'})
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. Tortoise SVN Clean up失败的解决方法

    step1: 到 sqlite官网 (http://www.sqlite.org/download.html) 下载 sqlite3.exe (找到 Precompiled Binaries for ...

  2. 黄聪:wordpress伪静态的原理

    首先起作用的是配置文件的.htaccess 中的 RewriteEngine OnRewriteBase /RewriteRule ^index\.php$ - [L]RewriteCond %{RE ...

  3. @property and retain, assign, copy, nonatomic解析

    nonatomic vs. atomic - "atomic" is the default. Always use "nonatomic". I don't ...

  4. VS 开发工具中的Remote Debug 功能远程调试程序经验分享

    前言: 有时候我们Dev(开发人员)需要debug tester(测试人员)或者customer(客户)的环境,可tester的机器上没有Code,是不是有点着急? 而且是多版本应用且tester 发 ...

  5. Maven打包web工程成WAR

    其实不一定要通过Goals:package来打war包,直接run as maven bulid也行:

  6. 玩转sublime(一)——玩转全局文件搜索/替换

    这个快捷键好记,一般的搜索是Ctrl+f,多了一个Shift就是全局搜索

  7. hdu 3068 最长回文 manacher算法(视频)

    感悟: 首先我要Orz一下qsc,我在网上很难找到关于acm的教学视频,但偶然发现了这个,感觉做的很好,链接:戳戳戳 感觉这种花费自己时间去教别人的人真的很伟大. manacher算法把所有的回文都变 ...

  8. 区分listview的item和Button的点击事件

    这两天修改领导通的ListView widget,在ListView中加入Button这类的有 “点击” 事件的widget,发现原来listview的itemclick居然失效了, 后来在网上查资料 ...

  9. contentprovider提供程序间共享数据的统一接口

    contentprovider提供程序间共享数据的统一接口

  10. KS-检验(Kolmogorov-Smirnov test) -- 检验数据是否符合某种分布

    Kolmogorov-Smirnov是比较一个频率分布f(x)与理论分布g(x)或者两个观测值分布的检验方法.其原假设H0:两个数据分布一致或者数据符合理论分布.D=max| f(x)- g(x)|, ...