[Tutor] Why None?

Christopher Spears cspears2002 at yahoo.com
Tue Feb 7 21:54:01 CET 2006


I get it!  Have printFood return a string!

def printFood(self):
		return self.food.foodName

Now I don't get the weird output anymore!

-Chris

--- Danny Yoo <dyoo at hkn.eecs.berkeley.edu> wrote:

> 
> Hi Chris,
> 
> I'm going to be a little insidous and bring some
> ideas from the textbook
> "How to Design Programs."  (http://htdp.org)
> 
> Let's annotate each interesting method with what the
> method expects to
> take in, and what it expects to return.
> 
> > 	def placeOrder(self, foodName, employee):
> 
> 
> We can say that placeOrder takes in foodName and
> employee, and returns
> None.  We can write this concept as a docstring,
> using a notation like
> this:
> 
> ##############################################
>     def placeOrder(self, foodName, employee):
>         """placeOrder: string Employee -> None
>         ... [add description here]"""
>         ## rest of body
> ##############################################
> 
> That is, we make it clear what the expected inputs
> and outputs are.
> 
> 
> > 	def printFood(self):
> 
> printFood doesn't appear to take anything useful,
> and also doesn't return
> anything useful.  Again:
> 
> ################################
>     def printFood(self):
>         """printFood: -> None"""
>         ## rest of body
> ################################
> 
> (Hint: this part is important.  Note that
> printFood() also returns None.)
> 
> 
> If you do this slight annotation to the rest of the
> methods, it might make
> it easier to see why Lunch.result() is giving
> slightly weird results.
> 
> 
> Best of wishes!
> 
> 


"I'm the last person to pretend that I'm a radio.  I'd rather go out and be a color television set."
-David Bowie

"Who dares wins"
-British military motto

"I generally know what I'm doing."
-Buster Keaton


More information about the Tutor mailing list