Welcome to programming!

Download Report

Transcript Welcome to programming!

Welcome to programming!
Python
Lesson one :set up /IDLE
interface/print / command
What is python?
• Python is a powerful object-oriented programming language that
can be used in a wide variety of applications. Python is one of the
family of 'P' languages widely used in web development, Python,
Perl, PHP.
Examples of Python applications:
• Web Development (CGI scripts, Content Management Systems)
• Database Access
• Desktop GUIs (windows)
• Scientific and Numeric Computing
• Low Level Network Programming
• Software Development
• Games and 3D Graphics
Lesson one-print and command
Today we are going to use the most basic of
features print and command.
Print will put information on a page
Open up python
Go to your program tree
Open up python 2.5
Open up the IDLE(pythons GUI)
The reason that we are doing this is that we need to open up the user interface(GUI)
What the GUI looks like
This is where you type your programming into
This is also where you run your program
Setting up Python
We are going to open up python
You should have selected IDLE to open up the user interface
Save a python file to your documents making sure the end of
the file is named .py
Save your python file as
Test.py
Open up a new window
Go to file –new window
Your programming window will now open up
print
Type print command
Print “this is a python string!”
Now press the f5 key to run your first program
When you run your program it shows the results in your GUI
Lesson two-user input
Empty
content of
the previous
program so
it looks now
like this
What we are going to do is type in some new code, that will require an INPUT
Type in the following code:
You need to now run this program you have written by pressing f5
User input continued…
Once you have selected f5 it will prompt you
to save.so save as user input.py
When you press f5 your
program will open up in the
interface and it will prompt
you to enter a number
User input continued…..
Now you have run your program it prompts you to enter a value in numbers
Enter your age then press enter-it will then tell you how old you are!
Conditional statementsif statement
“If age is bigger than 60 then print your are quite old”
Delete all previous code
And type in the
following code
Then press f5 to run it-save it as use of conditional statements.py
Your program once run will look like this
Using else statement
Delete your prior programs
and type in the following
program
Notice now we are using else as well as if
• When you type in an age above 60 you will get a message telling you ,you are
old
• When you type in an age below 60 you will get a message telling you ,you are
not that old
Looping…..
Open up IDLE-select file then new
Type in the following code
Then press f5
This will then print the
numbers 1-10
Looping cont….
To extend this we are going to type in this additional
code to create a second line of data
This printed one line of numbers 1-10
Now we are going to get python to
print a second line of data
Looping…….
The result of this is…………..
Two sets of data
Change the number at the end of the
code to 2 and see the effect
Looping…….
Now to get python to print squared numbers
Go to your previous window that looks like this….
Instead of the 0 type in o to
get python to print squared
numbers
This is what it looks like
Now you have a squared list of data
So –for ? In range(*enter parameter*) * what you want to be looped
Extension task-looping
This will create a list of data with next
to each number description as to if it is
odd or even
To see effect check next slide
What the lists look like
Now you can see the label
How to use functions in python
You need to type in the following
code exactly ,and make sure that
you have same spaces-EXACTLY
EXPLANATION:
YOU NEED TO DEFINE THE NUMBER
YOU ARE GOING TO SQUARE=X
Project 1-pass word reminder
You are now going to create a program to make
sure that you create a program and that the
password you have selected