Advertisement
MrsMcLead

ECS Functions

Nov 19th, 2013
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. from tkinter import *
  2. import tkinter.simpledialog
  3. import tkinter.messagebox
  4.  
  5. root = Tk()
  6. w = Label(root, text="Functions")
  7. w.pack()
  8.  
  9. #functions are defined below:
  10. def sayhello():
  11.     tkinter.messagebox.showinfo("sayHello", "Hello")
  12.  
  13. def saywelcome(name1, name2):
  14.     tkinter.messagebox.showinfo("sayWelcome", "Welcome " + name1 + " and " + name2)
  15.  
  16. def square(num):
  17.     answer = num * num
  18.     return answer
  19.  
  20. #The code starts running here.  This is where the methods are actually called:
  21. sayhello()
  22. saywelcome("Alicia", "Camille")
  23. squared = square(4)
  24. tkinter.messagebox.showinfo("square", "4 squared is " + str(squared))
  25.  
  26.  
  27. # Run the program and answer the questions below:
  28. #
  29. # 1. What does the function sayhello() do?
  30. #
  31. # 2. What does the function saywelcome() do?
  32. #
  33. # 3. What does the function square() do?
  34. #
  35. #
  36. #  Arguments are the things passed in ()'s.  For example, in the line:
  37. #  squared = square(4)
  38. #  4 is the argument to the method square
  39. #
  40. # 4. How many arguments does sayhello() take?
  41. #
  42. # 5. How many arguments does saywelcome() take?
  43. #
  44. #
  45. #  Functions may return information using the return statement.
  46. #
  47. # 6. What is returned from printwelcome()?
  48. #
  49. # 7. What is returned from square()?
  50. #
  51. # 8. Write your own function called cube().  It would be very similar to
  52. #    square but it would multiply the number times itself three times.
  53. #    Add some code to test it.
  54. #
  55. # 9. Extra Credit: Write your own function called area that takes one
  56. #    argument called radius.  It should find the area of a circle and return it.
  57. #   A = 3.14*r^2  
  58. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement