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

01 - Introduction To Python - Print Statements Data Types and Calculations

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

01 - Introduction To Python - Print Statements Data Types and Calculations

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 38

Introduction to Python

Programming

Part 1: Data Types,


Print Function and
Calculations
How to use this resource
Skill Explanations: Pink Slides
• Within each unit, you will learn how to develop
and apply a range of Python programming skills.
Skill explanations are in pink.
Tasks: Rookie Pro Beast
• After reading the explanation of a skill, apply it
within the given tasks. The tasks are categorised
into Rookie (Easy), Pro (Medium) or Beast (Hard).
Challenges: Rookie Pro Beast
• Once you have learned how to apply your new
skills, demonstrate your ability by completing the
given challenges. Don’t forget the debugging task!
• Once complete, review your performance!
Learning Objectives
Rookie
• To open and save a python program.
• To write simple print statements.
• To understand how to print different data types.
Pro
• To combine string and integers within a single print statement.
Beast
• To apply and combine python functions to improve programming
efficiency.
Skill Contents
Once you complete a skill, colour code Contents Confidence
the box to show your level of Level
confidence. You can always revisit the Data types (String & Integers)
skill later on to boost your confidence. Print function
Mathematical operations + - / *
Key Colour
Code Using the comma ,
Using the newline character \n
I am very good at this skill
and could show a friend
how to do it.
I am confident I can
perform this skill on my
own.

I need to improve my
understanding of this skill.
Data Types
• In programming, there are several different data types which can be used in
different ways.
• Within these initial introduction tasks, the two main data types you will use are
string and integers.

String Integer
Is a data type which represents Is a data type used to
Explanation text. represent whole numbers.
“Hello human, what is your 11, 22, 555, 234, 7654321
Example name?”

Note: String is always written in “quotation marks”.


Task 1: Understanding String and Integers
Within the table below, state if the data shown is a
string or an integer:
Data Data Type (String or Integer)
“I love coding!”
1000000
“1966”
“London hosted the 2012
Olympics”
Python Functions
• A Function is a section of code that performs a specific task.
• Python has many inbuilt functions which you will begin to
learn about as you progress through these introduction
activities.
• As a right of passage, the first piece of code all new
programmers need to write the famous computer science
phrase “Hello World”
• Within Python, to output a statement you need to use the
print function.
Understanding the Python Tasks
• In order to learn some of the key python functions and
programming techniques, you will complete a series of
programming tasks split into the levels: Rookie (easiest), Pro
(medium) and Beast (hardest).
• Afterwards, to assess your programming skills, you will
complete a series of python challenges to measure your
ability: Rookie, Pro or Beast.
• To help develop your understanding of programming, the
solution for each task is presented in both flowchart and
pseudo code.
Skill 1: Using the Print Function
• The python print function allows you to output information.
• You write it like this:

• Type the information you want to output within the brackets (parenthesis).

print string:

print integers:

Notes: String is written within quotation marks.


Integers don’t use quotation marks.
Task 2: Rookie
Output the famous programming phrase “Hello World”

Flowchart Pseudo code Python

START
OUTPUT: Hello World
END
Task 2: Solution
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Skill 2: Mathematical Operations
• Python allows you to conduct calculations. The following symbols are
used to conduct mathematical operations:

Addition +

Subtraction -

Division /

Multiplication *
We will investigate more uses for these symbols later on
Notes: within the skills development.
Task 3: Rookie
Output the answer to the following sum:
365*12
Flowchart Pseudo code Python

START
OUTPUT: 365*12
END
Task 3: Solution
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Task 4: Rookie
Write the following string statement and integer calculation:
“The answer to the sum 123 x 456 is: ”
123 * 456
Flowchart Pseudo code Python

START
OUTPUT: The
answer to the sum
123 x 456 is:
OUTPUT: 123 * 456
END
Task 4: Solution
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Task 5: Rookie
1. Python also allows you to use some mathematical operators with string
statements.
2. Make the statement “Hello World” repeat 10 times.
Flowchart Pseudo code Python

START
OUTPUT: Hello
World x 10
END
Task 5: Solution
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Skill 3: Using the Comma
• The comma is used to separate character sets, e.g. string and integers.
• Using a comma also creates an automatic space.

Code:

Output:

Notes: Using a comma allows you to output integers as part of


a string sentence.
Task 6: Pro
Output the following using an integer calculation and a comma , on the same line :
The answer to the sum 123 x 456 is: 56088

Flowchart Pseudo code Python

START
OUTPUT: The
answer to the
sum 123 x 456 is:
(123 x 456)
END
Task 6: Solution
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Task 7: Pro
Write the following using an integer calculation and a comma:
I only have [100-age] years to go until I reach 100!

Flowchart Pseudo code Python

START
OUTPUT: I only
have [100-age]
years to go until I
reach 100!
END
Task 7: Solution
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Skill 4: Using the \n function
• The newline character is used to split output statements onto separate
lines.
• You add it within string quotation marks.

Code:

Output:

Notes: As you can see, Python identifies the newline character


(\n) and splits the print output accordingly.
Task 8: Beast
Task: Write the following using the newline character \n :
“Hello World”
Flowchart Pseudo code Python

START
OUTPUT: Hello
World
END
Task 8: Solution
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Task 9: Beast
Task: Make the statement “Hello World” repeat 5 times, on
separate lines.
Flowchart Pseudo code Python

START
OUTPUT:
Hello World
Hello World
Hello World
Hello World
Hello World
END
Task 9: Solution
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Programming Challenges
• Now you have learned some programming skills, it’s time to
put them into practice!
• Complete the following programming challenges. Start with
the Rookie challenge and see how far you can push yourself.
• Finally, complete the debugging challenge.
• Once you have finished your challenges, complete the
review. Look back at the skills you have learned so far to help
you solve the challenge.
Add a print screen of
your solutions to the
Programming Challenge: Rookie next slide.

1. Write a piece of code to output the following statement:

1 Mark
2. Write a calculation which will output the following
number:

1 Mark
Programming Challenge: Rookie 1 - Answer
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Programming Challenge: Rookie 2 - Answer
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Add a print screen of
your solutions to the
Programming Challenge: Pro next slide.

Using two integer calculations to output the


information indicated below, write a piece of
code to output the following statement:

1 Mark
Programming Challenge: Pro - Answer
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Add a print screen of
your solutions to the
Programming Challenge: Beast next slide.

Using a suitable integer calculation to output the


information indicated below and only one code line,
write a piece of code to output the following two
lined statement:

Add a calculation to state how many


years ago World War 1 ended. 1 Mark
Programming Challenge: Beast - Answer
• Add a print screen to show • Add a print screen to show
your coding here. your output solution here.
Debugging Question
Which of the following lines of code below would output the following
statement:

Highlight the correct cell in green:

1 Mark
Complete the table below to help you identify what
Challenges Review areas you are confident at and which areas you need
to improve further:
Challenge Your Score (Max 1 mark each)
Rookie Challenge 1
Rookie Challenge 2
Pro Challenge
Beast Challenge
Debugging Challenge

Unit Review
What Went Well:

Even Better If:

You might also like