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 ...
随机推荐
- Tomcat在eclipse中起动成功,主页却打不开
症状: tomcat在eclipse里面能正常启动,而在浏览器中访问http://localhost:8080/不能访问,且报404错误.同时其他项目页面也不能访问. 关闭eclipse里面的tomc ...
- Redis配置文件解读
转载自:http://www.cnblogs.com/daizhj/articles/1956681.html 对部分配置选项做了一些说明 把配置项目从上到下看了一遍,有了个大致的了解,暂时还用不到一 ...
- C++ 常见崩溃问题分析
一.前言 从事自动化测试平台开发的编程实践中,遭遇了几个程序崩溃问题,解决它们颇费了不少心思,解决过程中的曲折和彻夜的辗转反侧却历历在目,一直寻思写点东西,为这段难忘的经历留点纪念,总结惨痛的教训带来 ...
- NeHe OpenGL教程 第十五课:纹理图形字
转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...
- 实现从sql server存取二进制图片
转:http://www.cnblogs.com/jeffwongishandsome/archive/2009/08/27/1554440.html 1.存取图片(1).将图片文件转换为二进制并直接 ...
- ubuntu vi上下左右键无法使用?
使用vm安装ubuntu出现vi上下左右键无法正常使用. 执行以下两句就可以了 $sudo apt-get remove vim-common $sudo apt-get install vim
- LInux SSH远程文件/目录传输命令scp(转载)
From:http://www.vpser.net/manage/scp.html 相信各位VPSer在使用VPS是经常会在不同VPS间相互备份数据或转移数据.一般情况下VPS都已安装了Ngnix或者 ...
- iOS8 StoryBoard 连线diss方法
添加自定义Dismiss类: // Dismiss.h // StoryBoardTest // // Created by zhujin on 14/12/23. // Copyright ...
- python 读取文本
将文本转换到NumPy 数组中,做机器学习或其他任何任务,文本处理的技能必不可少.python 实现实现了很精简强大的文本处理功能: 假设 文件 traindata.csv 中有数据 1000行,3列 ...
- 解决mysql"Access denied for user'root'@'IP地址'"问题
在另一台服务器使用 MySQL-Front链接时: 解决方法: 在MySQL服务器上使用root登录后,执行如下SQL语句: mysql 登录命令: >mysql -u root -p; 然后执 ...