Python 4
Python 4
Python 4
Computing: IntroductiontotoPython
Python
Lesson Three : four
Lesson
Learning Objective
• To use a textual programming language to solve a variety of
computational problems.
Success Criteria
• To Revise data types.
• To practice in Python to : enabling numerical inputs.
• To understand the importance of annotating code.
Let’s Bring It All Together
Variables
We can think of variables as like boxes. Each box has a label, and we can
store information (data) in each box. This information can vary during the
running of a program. The boxes are emptied of data when the program
ends.
Data Types
Python has four data types:
•String (text or alphanumeric information);
•Integer (a whole number, a number which is not a fraction);
•Float (a number which can be a fraction);
•Boolean (can only be one of two values, True or False).
Key Terms
Adding strings together is
called concatenation
(con - cat - en - ay - shun).
Awesome Annotation
• So far, our Python programs have been quite short.
• More complex programs can have hundreds of lines of code (or even
thousands).
• When programs start to get longer, or if we come back to a program that
we’ve not looked at for a while, it’s easy to forget how our code works or
why we did things in a certain way.
• Therefore, we need a method to help us remember what our code does, and
to explain it to others.
• Programmers use annotation to explain their code.
• It’s very easy to add annotation. In Python, we use a # (you might call it a
hashtag…) at the start of each line of annotation.
• When we run our programs, Python ignores any lines that start with a #.
• Annotation is for humans, not computers.
• Using annotations is very good programming practice, and will help you make
less errors with your code. Let’s add annotation to our program…
Awesome Annotation
You can add as many lines of annotation as you like.
Notice how Python IDLE changes annotation lines into red.
Snakes Alive!
• The Python programming language first appeared in February 1991.
• In a sense, we could say that this was when Python was born.
• Have you ever wondered how many days you’ve been alive?
Or hours, minutes or seconds?
Annotation
Programmers use annotation to explain their code.
Annotation is useful for when programs start to get longer,
or if we come back to a program that we’ve not looked at for a while.
In Python we use a # at the start of each line of annotation.
When we run our programs, Python ignores any lines that start with a #.
Annotation is for humans, not computers. Using annotation is very good
programming practice, and will help you make less errors with your code.
Rate Your Progress
Red Light: you have understood some of the objective
and you will think about it some more later on, perhaps
asking a friend or teacher for help.
Green Light: you feel fully confident with this objective and
you understand it well.
Success Criteria:
• To know why programming languages use data types.
• To use type casting in Python to enable numerical inputs.
• To understand the importance of annotating code.
Nailing It Down
We have learned a lot today about data types and annotation in Python.
There are many other programming languages, some are easier to learn
than others.
You can find out about different languages at this interesting website:
http://rosettacode.org/wiki/Rosetta_Code
The purpose of this website is to present solutions to the same problems
for lots of different programming languages.