0% found this document useful (0 votes)
623 views

Classes

This document provides instructions for creating a Person class in Python with attributes like name, age, and place of birth. It describes initializing an instance of the Person class by setting attribute values, and includes an example method called introduce_yourself() that prints a statement with the person's attributes. The document also defines key programming concepts like classes, objects, instances, scope, and different types of variables in classes.

Uploaded by

api-291204383
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
623 views

Classes

This document provides instructions for creating a Person class in Python with attributes like name, age, and place of birth. It describes initializing an instance of the Person class by setting attribute values, and includes an example method called introduce_yourself() that prints a statement with the person's attributes. The document also defines key programming concepts like classes, objects, instances, scope, and different types of variables in classes.

Uploaded by

api-291204383
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 1

LESSON: 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

Member Variables - variables that are only available to members of a


certain class
Instance Variables - variables that are only available to particular
instances of a class
Method- a function within a class
Inheritance- a derived or subclass

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.

You might also like