0% found this document useful (0 votes)
31 views7 pages

Year 7 Python Syntax and Basics Guide

The Year 7 Python Revision Booklet covers essential Python programming concepts including syntax, data types, input/output functions, operators, variables, assignment statements, and selection statements. It provides examples and exercises for each topic to reinforce learning. The booklet aims to help students understand the basics of Python programming through practical coding exercises.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views7 pages

Year 7 Python Syntax and Basics Guide

The Year 7 Python Revision Booklet covers essential Python programming concepts including syntax, data types, input/output functions, operators, variables, assignment statements, and selection statements. It provides examples and exercises for each topic to reinforce learning. The booklet aims to help students understand the basics of Python programming through practical coding exercises.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Year 7 Python Revision Booklet

Syntax
Python is a set of rules that define how a python
program must be written, the pythons interpreter
should understand and execute it correctly.
Examples of Correct Syntax:

Data Types:

 Integers (int) - Whole numbers, positive or negative.

Example: 5, -42, 1000

 Float (float) - Numbers with a decimal point.

Example: 3.14, -0.001, 2.0

 Boolean (bool) - Represents True or False.

Often used in conditional statements.

 String (str) - A sequence of alphanumeric characters enclosed in


quotes.

Example: "hello", 'Python'

Example of Code:

1. Outputs
In Python, you can use the print() function to display output.

Example:

Code Explanation - print() is a built-in function in Python used to display


text or values on the screen. "Hello, World!" is a string (text) that will be
shown in the output. This line tells Python to show the message: Hello,
World!

Exercise:
Write a Python program to print your name.

2. Inputs
You can use the input() function to get user input.

Examples:

Code Explanation - input("Enter your name: ") shows a message and waits
for the user to type something. Whatever the user types is stored in the
variable name. print("Hello,", name) displays a greeting using the value
stored in name. Example: If the user types Ali, the output will be: Hello, Ali

Exercise:

a. Describe what is happening in the code below:

b. Write a Python program to ask for your age and display it.

3. Operators
Operators are used to perform operations on variables and values. There 3
main types of operators. These include Arithmetic, Comparison and
Logical.

Arithmetic Operators - are used to perform mathematical operations.

Operator Description Example

+ Addition a + b

- Subtraction a - b

* Multiplication a * b

/ Division (float) a / b

// Floor Division (returns a // b


whole number)

% Modulus (returns a % b
remainder)

** Exponentiation a ** b
(Powers of)

Comparison Operators – are used to compare two values to check if


they are:

Operator Description Example

== Equal to a == b

!= Not equal to a != b

> Greater than a > b

< Less than a < b

>= Greater or equal a >= b

<= Less or equal a <= b

Assignment Operators – used to store (assign) a value to a variable to


use later.
Operator Description Example

= Assign a = b

Examples:

Code Explanation –

 + is the addition operator: adds two numbers.


 * is the multiplication operator: multiplies two numbers.
 > is a comparison operator: checks if one value is greater than
another.
 print() shows the result of each operation.
 The Output:

Exercise:

a. Describe what is happening in the code below:

b. Write a Python program to perform addition, subtraction,


multiplication, and division.

4. Variables
Variables are used to store data values.

Examples:

Code Explanation –

 name and age are variables: containers that store data.


 "Alice" is a string, and 12 is an integer.
 print() combines the values and displays a sentence.
 The Output:

Exercise:

Write a Python program to create variables for your name, age, and
favourite colour.

5. Assignment Statements

Assignment statements are used to assign values to variables.

Examples:

Code Explanation –

 a = 5 assigns the value 5 to the variable a.


 b = 10 assigns 5 to b.
 c = a * b multiplies a and b, and stores the result in c.
 print() shows the final result.
 The output

Exercise:

Write a Python program to assign values to variables and perform


arithmetic operations.

6. Selection Statement

Selection statements are used to make decisions in a program. These


include the use of an IF Statement, IF Else Statement, IF ELIF Else
Statement.

Examples:

IF Statement - This checks if a number is greater than 10.

Code Explanation - If the condition number > 10 is true, the message is


printed. If it's false, nothing happens.

IF Else Statement - This checks if a number is even or odd.

Code Explanation - % is the MOD


operator (look at your notes in
your exercise book). It checks
the remainder. If the number
divided by 2 has no remainder,
it's even. Otherwise, it's odd.

IF ELIF Else Statement: The program below checks a student's grade


based on their score.
Code Explanation - The
program checks each
condition in order. As soon as
one condition is true, it runs
that block and skips the rest.
If none of the if or elif
conditions are true, the else
block runs.

Exercise:

Write a Python program to check if a number is positive, negative, or zero.

You might also like