Gr 6.6 Introduction to Python 5
Gr 6.6 Introduction to Python 5
Lesson One
Learning Objective
• To use a textual programming language to solve a variety of
computational problems.
Success Criteria
• To know how to start Python IDLE and run a Python program.
• To use Python to perform calculations.
• To write simple programs that respond to user input.
The Full Monty
Meet Monty.
Monty is a snake.
To be more specific, Monty is a python.
Interactive Script
Computer programs become much more interesting and useful when they
can respond to user input.
• input is our next Python command. It waits for the user to type in
something, in this case we are asking the user to type in their name.
• What happens to the name that is typed in?
• Answer: not much at the moment!
• There is something that happens though, we just can’t see it yet…
Incredible Inputs
To understand what’s going on, let’s look back at the Python
code we entered:
Try out the following code in Python and see what happens:
• Take care with your typing, watch our for the commas and quotes!
“Monty”
Interactive Script
• Click on File
“Monty” “Monty”
What is your name? Monty
How are you today? not bad”
“not bad at all
What is your favourite food?“chips”
fish and chips
Greetings Monty
I hear that you are feeling not bad at all
Maybe you need tasty fish and chips to eat?
“not bad”
“chips”
Success Criteria:
• To know how to start Python IDLE and run a Python program.
• To use Python to perform calculations.
• To write simple programs that respond to user input.
DATA TYPE
TYPES OF DATA TYPE
Operators
Operators are used to perform operations on
variables and values.
Python divides the operators in the following
groups:
•Arithmetic operators
•Comparison operators
•Logical operators
Arithmetic operators
Arithmetic operators are used with numeric
values to perform common mathematical
operations:
Comparison operators
Comparison operators are used to compare two
values:
Logical operators
Logical operators are used to combine conditional
statements:
Python Comments
Creating a Comment
#This is a comment
print("Hello, World!")
Example
print("Hello, World!") #This is a comment
1.Sequencing: This means that the computer will run your code in order,
one line at a time from the top to the bottom of your program. It will start
at line 1, then execute line 2 then line 3 and so on till it reaches the last
line of your program.
Output:-
2.Selection: Sometimes you only want some lines of code to be run only if
a condition is met, otherwise you want the computer to ignore these lines
and jump over them. This is achieved using IF statements. e.g. If a
condition is met then lines 4, 5, 6 are executed otherwise the computer
jumps to line 7 without even looking at line 4,5 and 6.
Syntax:-
if(condition):
statement 1
else:
statement 2
Example-
#To check whether the number is greater or not.
num1=int(input("enter first number"))
num2=int(input("enter second numbers"))
if num1>num2:
print(num1,"is greater")
else:
print(num2,"is greater")
Syntax for elif :-
if (condition1):
statement 1
elif (condition2):
statement 2
elif (condition3):
statement 3
else:
statement 4
Example-
#To check whether the number is greater among three numbers.
num1=int(input("enter first number"))
num2=int(input("enter second number"))
num3=int(input("enter third number"))
if(num1>num2 and num1>num3):
print(num1, "is greater")
elif(num2>num1 and num2>num3):
print(num2, "is greater")
elif(num3>num1 and num3>num2):
print(num3, "is greater")
else:
print("invalid input")
Nailing It Down
We have learned a lot today about Python IDLE, print and input.
Python is a great programming language to learn.
You can download it yourself at home for free by visiting:
https://www.python.org/downloads/
(or just search for ‘python’ using your favourite search engine).
There are also lots of free online versions of Python which are great for
learning how to code. Try out some of these links now:
• https://snakify.org/
• http://pythontutor.com/
• https://hourofpython.com/
• https://repl.it/languages/python3
Good luck for your
Mini project.
THANK YOU