Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. Code
  2. -----------
  3. def say_hello(input_func):
  4.     name = input_func()
  5.     return "Hello " + name
  6.  
  7. def prompt_for_name():
  8.     return raw_input("What is your name? ")
  9.  
  10. print say_hello(prompt_for_name)
  11.  
  12. Testing
  13. -----------
  14. def test_say_hello():
  15.     output = say_hello(lambda: "Random Name")
  16.     assert(output == "Hello Random Name")
  17.  
  18.  
  19. OR
  20.  
  21. Code
  22. -----------
  23. def say_hello():
  24.     if __name__ == '__main__':
  25.         name = raw_input("What is your name? ")
  26.     else:
  27.         name = 'Random Name'
  28.     return "Hello" + name
  29.  
  30. Testing
  31. -----------
  32. def test_say_hello():
  33.     output = say_hello()
  34.     assert(output == "Hello Random Name")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement