Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- import tkinter.simpledialog
- import tkinter.messagebox
- root = Tk()
- w = Label(root, text="Functions")
- w.pack()
- #functions are defined below:
- def sayhello():
- tkinter.messagebox.showinfo("sayHello", "Hello")
- def saywelcome(name1, name2):
- tkinter.messagebox.showinfo("sayWelcome", "Welcome " + name1 + " and " + name2)
- def square(num):
- answer = num * num
- return answer
- #The code starts running here. This is where the methods are actually called:
- sayhello()
- saywelcome("Alicia", "Camille")
- squared = square(4)
- tkinter.messagebox.showinfo("square", "4 squared is " + str(squared))
- # Run the program and answer the questions below:
- #
- # 1. What does the function sayhello() do?
- #
- # 2. What does the function saywelcome() do?
- #
- # 3. What does the function square() do?
- #
- #
- # Arguments are the things passed in ()'s. For example, in the line:
- # squared = square(4)
- # 4 is the argument to the method square
- #
- # 4. How many arguments does sayhello() take?
- #
- # 5. How many arguments does saywelcome() take?
- #
- #
- # Functions may return information using the return statement.
- #
- # 6. What is returned from printwelcome()?
- #
- # 7. What is returned from square()?
- #
- # 8. Write your own function called cube(). It would be very similar to
- # square but it would multiply the number times itself three times.
- # Add some code to test it.
- #
- # 9. Extra Credit: Write your own function called area that takes one
- # argument called radius. It should find the area of a circle and return it.
- # A = 3.14*r^2
- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement