welcome to programming!

24
Welcome to programming! Python Lesson one :set up /IDLE interface/print / command

Upload: drew

Post on 25-Feb-2016

21 views

Category:

Documents


0 download

DESCRIPTION

Welcome to programming!. Python Lesson one :set up /IDLE interface/print / command. What is python?. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Welcome to programming!

Welcome to programming!

Python

Lesson one :set up /IDLE interface/print / command

Page 2: Welcome to programming!

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

Page 3: Welcome to programming!

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

Page 4: Welcome to programming!

Open up python

Go to your program tree Open up python 2.5Open up the IDLE(pythons GUI)

The reason that we are doing this is that we need to open up the user interface(GUI)

Page 5: Welcome to programming!

What the GUI looks like

This is where you type your programming into

This is also where you run your program

Page 6: Welcome to programming!

Setting up PythonWe are going to open up pythonYou should have selected IDLE to open up the user interfaceSave a python file to your documents making sure the end of the file is named .py

Save your python file as Test.py

Page 7: Welcome to programming!

Open up a new window

Go to file –new windowYour programming window will now open up

Page 8: Welcome to programming!

printType print command Print “this is a python string!”

Now press the f5 key to run your first programWhen you run your program it shows the results in your GUI

Page 9: Welcome to programming!

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

Page 10: Welcome to programming!

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

Page 11: Welcome to programming!

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!

Page 12: Welcome to programming!

Conditional statements-if 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

Page 13: Welcome to programming!

Your program once run will look like this

Page 14: Welcome to programming!

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

Page 15: Welcome to programming!

Looping…..

Open up IDLE-select file then new Type in the following codeThen press f5

This will then print the numbers 1-10

Page 16: Welcome to programming!

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

Page 17: Welcome to programming!

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

Page 18: Welcome to programming!

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

Page 19: Welcome to programming!

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

Page 20: Welcome to programming!

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

Page 21: Welcome to programming!

What the lists look like

Now you can see the label

Page 22: Welcome to programming!

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

Page 23: Welcome to programming!

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

Page 24: Welcome to programming!