03-Introduction to python syntaxes .pptx

ThilinaWanshathilaka1 0 views 14 slides Oct 11, 2025
Slide 1
Slide 1 of 14
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14

About This Presentation

Introduction to python syntaxes


Slide Content

03-Python Syntax By Thilina Wanshathilaka

What is Syntax Every natural language has set of syntax to create well-formed coherent messages. These rules are defined by the grammar. By not following these rules may create confusion and misunderstanding. Same as we do have accepted structure when issue commands to computer. Not following these rules may cause program to not operate properly

Python Syntax There are few number of elements in python syntax paradigm Statements Comments Reserve words Variables Indentation or code blocks

Statement The lines that are execute by the python interpreter is called statement . These statement contain the instruction achieve particular task There hard rules have set up when writing statements. Through out this program we will learn how to write the python statements accurately.

Comments In Python, the hash mark (#) indicates a comment. Anything following a hash mark in your code is ignored by the Python interpreter. The main reason to write comments is to explain what your code is supposed to do and how you are making it work . This is important to refer it later

Single-line Vs Multi-line comments There are two types of comments single line comments which followed by # sign and multi-line comment which write between six single quotations as three at the start and three at the end Single-line comments Multi-line comments

Keywords /Reserve words The following list shows the Python keywords. These are reserved words and you cannot use them as constant or variable or any other identifier names.

Variables Variable are labels that hold specific values required for the program. There are number of rules while labeling python variable. Not following these are cause throw an error when executing program Variable name are case sensitive so Name and name is two different variable Also there are certain rule defined by firms for quality control breaking these rules may not cause errors

Indentation/Code block Code blocks are very important aspect of structured programming If you are familiar with other programming languages such as java ,C# ,C or C++ you use {} to represent code blocks But in python we use indentation as code block. The way create indentation is either pressing tab onetime or press space bar three time(preferred ) We can see indentations in conditionals (If Else), repetitions(Loops) and functions which we will discuss later

Indentation/Code block We will check how to create code with some conditions. By doing that we learn about indentation. This is a program to check the number input by the use is less than 10 or 10 or greater than 10

Function/Methods Function/Method is a codes block that contain some process to call upon when needed. Functions and Methods reduce the length of code and improve the reusability of application In python we start function/method with def keyword I t is a code block so after define method we use indentation for the statements belong to that method

Function/Methods This is a program with method contain calculate aria of circle when input radiuses .

Challenge2.py Use input () to get the height and weight from user in meters and kilograms so you need to convert it to float value Calculate BMI value in the main program or as a function BMI= weight/ height*height Use if conditions to check following condition and print person is underweight, healthy etc. BMI<17.0 =underweight BMI>=17.0 and <25.0 =Healthy BMI>=25.0 and <35.0 =overweight BMI>=35.0 =Obese Write multiline comments on top of the program explaining what it dose and single line comment in every statements

Challenge2.py
Tags