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 ...
随机推荐
- win8以管理员身份安装软件
win8以管理员身份安装软件 msiexec /package
- Linux下nice/renice命令小结
1. nice命令 内核根据进程的nice值决定进程需要多少处理器时间. nice值的取值范围是是: -20到20. 一个具有-20 的 nice 值的进程有很高的优先级. 一个 nice 值为 20 ...
- 无法找到类:java.lang.ClassNotFoundException: com.tt.javaweb.HttpServletRequest问题解决
问题如下:找不到Httpservlet对应的Class,进入build目录下发现确实没有对应的class文件. 严重: Allocate exception for HttpServletReques ...
- java工程师分享:我是如何自学成才的?
原文:http://www.java800.com/peixun-79062115.html 我是10年河南工业大学的毕业生,当时我们专业许多学生都去报了java培训机构,去达内的都不少.我也想去培训 ...
- “代理 XP”组件已作为此服务器安全配置的一部分被关闭。解决方法
新建维护计划的时候遇到下图的报错信息 标题: Microsoft SQL Server Management Studio------------------------------ “代理 XP”组 ...
- Hadoop学习4--安装Hadoop
首先献上Hadoop下载地址: http://apache.fayea.com/hadoop/core/ 选择相应版本,点一下,直接进行http下载了. 对原来写的一篇文章,相当不满意,过于粗糙了,于 ...
- ThreadPoolExecutor使用介绍
private static ExecutorService exec = new ThreadPoolExecutor(8, 8, 0L,TimeUnit.MILLISECONDS, new Lin ...
- OAF_架构MVC系列1 - MVC的概述(概念)
2015-04-03 Created By BaoXinjian
- NeHe OpenGL教程 第十八课:二次几何体
转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...
- 基于redis的分布式锁
<?php /** * 基于redis的分布式锁 * * 参考开源代码: * http://nleach.com/post/31299575840/redis-mutex-in-php * * ...