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 ...
随机推荐
- erlang的escript脚本
参考霸爷的博客 测试例子 #!/usr/bin/env escript %%! -smp enable -sname mmcshadow -mnesia debug verbose[/color] m ...
- sql语句延时执行或者是指定时间执行
--使用waitfor语句延迟或暂停程序的执行 --waitfor{delay'time'|time 'time'} delay是指间隔时间 最长到24小时 time是指定时间执行 waitfor d ...
- Objective C SEl 和@selector是怎么工作的||How do SEL and @selector work in iphone sdk?
SEL is a type that represents a selector in Objective-C. The @selector() keyword returns a SEL that ...
- SecureCRT控制台显示中文字符的设置
- SpringMVC控制器设值原理分析(ModelAndView的值通过HttpServletRequest直接取到的原因)
@RequestMapping("/userlist.do") public String getUserList(Model model){ HttpServletRequest ...
- Linux命令(15)查看系统版本信息
一,查看Linux内核版本命令(两种方法) 1.cat /proc/version [user@fgejjw7Z home]$ cat /proc/version Linux version -.el ...
- 转_ _android开发中如何结束所有的activity
每一个activity都有自己的生命周期,被打开了最终就要被关闭. 四种结束当前的activity方法 Java代码: //关闭当前activity方法一 finish(); //关闭当前界面方法 ...
- 安装java开发环境jdk,安装JDK
JDK可以理解为翻译官,它将Java高级语言翻译为二进制执行. JDK可以编译文件,编译后的文件扩展名为.class. 只要能支持JDK的地方,JAVA就可以运行,这就是JAVA跨平台的性质. 我的是 ...
- git fetch和git pull(转载)
From:http://www.tech126.com/git-fetch-pull/ Git中从远程的分支获取最新的版本到本地有这样2个命令: 1. git fetch:相当于是从远程获取最新版本到 ...
- 检测是否安装有sim卡
ios7测试ok [CTSIMSupportGetSIMStatus() isEqualToString:kCTSIMSupportSIMStatusNotInserted]可以判断是否插入了sim卡 ...