Classes
Classes
PROGRAMMING EXERCISES
(Requires IDLE 2.7.10)
Class - A description or definition of a type of thing. In program- ming
terms, a class is a collection of methods (behavior) and variables
#1: Person Class
(attributes).
Define a Person() class.
In the __init()__ function, define the following attributes of a person: name, age,
Object - The specific instance of a class.
place of birth, and anything else you like to know about the people in your life.
Write one method. This could be as simple as introduce_yourself(). This method
Instance - initialize Refers to setting up the initial state of an object
would print out a statement such as, print "Hello, my name is %s. I am %s. My place
of birth is %s " % (self.name,self.age,self.place_of_birth).
Scope - The part, or section, of a program where a variable can be
Create a person, set the attribute values appropriately, and print out information
seen (or used)
about the person. Call your method, introduce_yourself(), on the person you created.
Make sure your method executed properly
Global Variables - variables that are available everywhere
VOCABULARY
PROGRAMMING CHALLENGE # 7
(Prerequisite: Completed File Input and Output)
Guess the Number
Youre going to make a Guess the Number game. The computer will
think of a random number from 1 to 20, and ask you to guess it. The
computer will tell you if each guess is too high or too low. You win if you
can guess the number within six tries. This is a good game to code
because it uses random numbers, loops, and input from the user in a
short program.