Python- Recap(2)+ IF(2)
Good Morning boys.
Let us take a recap of Identifiers and the rules to forming valid identifiers:
--------------------------------------------------------------------------------------------------------------------------
The Google meet link for
By the end of this session, you will be able to
Today our focus will be the concept of identifiers.
(Please take down the following concepts in your registers):
- Define the term "Identifiers"
- Identify the rules to define identifiers
- Define identifiers as per the need of the program.
- Identify VALID and INVALID identifiers
- understand the application of input() and output() functions.
Today our focus will be the concept of identifiers.
(Please take down the following concepts in your registers):
As you know that identifiers are
- very important in programming.
- the building blocks of a program.
- So we need to create them wisely.
RULES to follow while defining identifiers
1.
1. Identifiers can be a combination of letters in lowercase (a to z) or uppercase (A to Z) or digits (0 to 9) or an underscore _ Names like myClass, var_1 and print_this_to_screen, all are valid example.
1 2. An identifier cannot start with a digit. eg. 1variable is invalid, but variable1 is perfectly fine.
2 3. Keywords cannot be used as identifiers. eg. print cannot be used as an identifier.
3 4. We cannot use special symbols like !, @, #, $, % etc. in our identifier. The only symbol allowed is the underscore i.e. "_" eg. var_1
4 5. An identifier can be of any length.
1. Python is a case-sensitive language. This means, Variable and variable are not the same. Always name identifiers that make sense.
2. While, c = 10 is valid. Writing count = 10 would make more sense and it would be easier to figure out what it does even when you look at your code after a long gap.
3. Multiple words can be separated using an underscore, this_is_a_long_variable.
The following are some VALID identifiers:
MyFile
MYFILE
CHK
Z2t0Z29
DATE9_7_77
_DS
FILE13
HJI3_JK
The following are some INVALID identifiers( along with the reason):
DATA-REC- contains special character – (hyphen) (other than A-Z,a-z,_(underscore))
29CLCT- starting with a digit
break - reserved word
My.file – contains special character dot (.)
_________________________________________________________________________________
By the end of the session today, you will be able to understand
(The content needs to be copied in registers)
NOTE- The content of the blog is available even after the class is over. In case you are unable to copy, Come back and complete after the other classes are over)
We know that the data processing goes through 3 stages in order to convert DATA into the desired INFORMATION-
1. INPUT
2. PROCESSING
3. OUTPUT
So, in order to solve any problem , the programmer has to identify:
1. What he wants the program to give ( desired output-INFORMATION)?
2. What is the input needed(DATA needed ) ?
Once this is done, the programmer has to perform the following steps:
1. create variables to accept data from the user. (Following the rules of forming identifiers as discussed yesterday).
2. Accept values from the user (Using INPUT() function)
3. Follow steps to do the necessary processing. (Using assignment statements)
4. Display the result to the user. (Using OUTPUT() function)
One very important point at this stage is discuss the importance of "Comments".
A comment is text that doesn’t affect the outcome of a code, it is just a piece of text to let someone know what you have done in a program or what is being done in a block of code. This is especially helpful when someone else has written a code and you are analysing it for bug (error) fixing or making a change in logic, by reading a comment you can understand the purpose of code much faster then by just going through the actual code.
_________________________________________________________________________________
By the end of the session today, you will be able to understand
- Importance of identification of desired output
- Importance of understanding the input needed for the desired purpose.
- The 3 stages of information processing
- The purpose/need for input( ) and Print( ) functions
- Step by step breaking down of processing statement
- Purpose and types of COMMENT statements.
(The content needs to be copied in registers)
NOTE- The content of the blog is available even after the class is over. In case you are unable to copy, Come back and complete after the other classes are over)
We know that the data processing goes through 3 stages in order to convert DATA into the desired INFORMATION-
1. INPUT
2. PROCESSING
3. OUTPUT
So, in order to solve any problem , the programmer has to identify:
1. What he wants the program to give ( desired output-INFORMATION)?
2. What is the input needed(DATA needed ) ?
Once this is done, the programmer has to perform the following steps:
1. create variables to accept data from the user. (Following the rules of forming identifiers as discussed yesterday).
2. Accept values from the user (Using INPUT() function)
3. Follow steps to do the necessary processing. (Using assignment statements)
4. Display the result to the user. (Using OUTPUT() function)
One very important point at this stage is discuss the importance of "Comments".
A comment is text that doesn’t affect the outcome of a code, it is just a piece of text to let someone know what you have done in a program or what is being done in a block of code. This is especially helpful when someone else has written a code and you are analysing it for bug (error) fixing or making a change in logic, by reading a comment you can understand the purpose of code much faster then by just going through the actual code.
Types of Comments in Python
There are two types of comments in Python.
1. Single line comment
2. Multiple line / Multi-line comment
1. Single line comment
2. Multiple line / Multi-line comment
Single line comment
In python we use # special character to start the comment. Lets take few examples to understand the usage.
# This is just a comment. Anything written here is ignored by Python
Multi-line comment:
To have a multi-line comment in Python, we use triple single quotes at the beginning and at the end of the comment, as shown below.
'''
This is a
multi-line
comment
'''
Python Comments Example
In this Python program we are seeing three types of comments. Single line comment, multi-line comment and the comment that is starting in the same line after the code.
''' We are writing a simple program here First print statement. This is a multiple line comment. ''' print("Hello Guys") # Second print statement print("How are You all?") print("Welcome to BeginnersBook") # Third print statement
Output:

# character inside quotes
When # character is encountered inside quotes, it is not considered as comment. For example:
print("#this is not a comment")
Output:
#this is not a comment
EXERCISE
NOTE:
1. An even number is a number which on division by 2 will leave no remainder.(i.e.remainder=0)
2. An ODD number is a number which on division by 2 will leave some remainder (i.e.remainder is not =0)
Write a program in Python to accept a number from the user and find whether it is even or odd.

Good morning maam
ReplyDeleteRahul
Good morning ma'am
ReplyDeleteTejas
Pls join the meet class immediately after marking your attendance
ReplyDeleteGood morning mam
ReplyDelete-Aaron David
You are missing the Meet class so no attendance
DeleteGood morning mam
ReplyDelete-
good morning maam
ReplyDeleteGOOD MORNING MA'AM
ReplyDelete-ARTHAM
Good morning ma'am
ReplyDelete-Geet
Excellent response by Tejas today. Proud of you
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHello maam it's Brian
ReplyDelete