Exercises - Kangaroo
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的更多相关文章
- [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 ...
- 6656 Watching the Kangaroo
6656 Watching the KangarooDay by day number of Kangaroos is decreasing just liketiger, whale or lion ...
- 46 Simple Python Exercises (前20道题)
46 Simple Python Exercises This is version 0.45 of a collection of simple Python exercises construct ...
- 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 ...
- 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 ...
- 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 ...
- 100 numpy exercises
100 numpy exercises A joint effort of the numpy community The goal is both to offer a quick referenc ...
- 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 ...
- E - Cheap Kangaroo(求多个数的最大公约数)
Description There are N kangaroos going out to eat at an Indian restaurant. The ith kangaroo wants t ...
随机推荐
- C#调用MySql
1.要连接MySql数据库必须首先下载MySql官方的连接.net的文件,文件下载地址为http://dev.mysql.com/downloads/connector/net/6.6.html#do ...
- 【java】之转码
GBK->UTF-8 String str = "任意字符串"; str = new String(str.getBytes("gbk"),"u ...
- TCP/IP四层模型和OSI七层模型的概念
转:http://blog.csdn.net/superjunjin/article/details/7841099/ TCP/IP四层模型 TCP/IP是一组协议的代名词,它还包括许多协议,组成了T ...
- .NET中值得体验的精妙设计
转自: http://developer.51cto.com/art/201104/255455_all.htm .NET 是 Microsoft XML Web services 平台.MEF是.N ...
- Microsoft Visual SourceSafe
Microsoft Visual SourceSafe是美国微软公司出品的版本控制系统,简称VSS.软件支持Windows系统所支持的所有文件格式,兼容Check out-Modify-Check i ...
- spring学习笔记2(转)
1.在Java开发领域,spring相对于EJB来说是一种轻量级的,非侵入性的Java开发框架,曾经有两本很畅销的书<Expert one-on-one J2EE Design and Deve ...
- BOM(Bill of Material)详解
一.物料(ITEM) 物料(Item or Material),是对存货的统称,是建立BOM和其他业务数据的前提条件,在ERP系统中称之为物料主数据,包括原材料(Raw material).在产品(W ...
- bug_ _图片_android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
=========== 1 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zgan.communit ...
- 转__Android Studio ,基于intellij idea
看到论坛里一些关于Android Studio的帖子,基本上是停留在使用教程上.在此做一些功能性的分析和测评 下载地址 :http://developer.android.com/index.html ...
- NoSQL分类及ehcache memcache redis 三大缓存的对比
NoSQL分类 由于NoSQL中没有像传统数据库那样定义数据的组织方式为关系型的,所以只要内部的数据组织采用了非关系型的方式,就可以称之为NoSQL数据库.目前,可以将众多的NoSQL数据库按照内部的 ...