Key points of chapter-4 Programming: it all adds up:
Conditional structure is a type of structure that begins with ‘if’ and then
has a logical test.
Each and every conditional statement and loop statements must end with
‘:’ (colon)
All the commands that follow the colon will be indented. That means
they will be sent from the left of the file window.
The program commands that handle inputs and outputs are called the
interface.
Keywords are the reserved words by the python, these words are used to
perform different tasks in the programming. Example: if,
while,for,else….etc.
If and else: if condition has 2 blocks, one block is to execute some set of
statements if the given condition is true, and the other block is to execute
some set of statements if the given condition of false.
Example: if answer==’Y’:
Result=a+b
If answer==’N’:
Tesult=a-b
Loops: Loop is a concept used to repeat the same set of statements
multiple number of times. These loops are used to reduce the number of
statements. In python we have 2 different types of loops
1) Counter loop(also called as fixed loop)
2) Conditional loop
Counter loop repeats the given statements up to a certain number and then
stops. ‘for’ loop is the best example of counter loop.
Conditional loop repeats the given statements as long as the given
condition is satisfied. ‘while’ loop is the best example of condition loop.
Example: For I in range(1,10):
Print(i)
Example: while I<=10:
Print(i)
Errors: In general an error means a mistake, in programming language if
we didn’t follow the rules, those mistakes are called as syntax errors.
syntax means the rule.
Logical error: a logical error is an error which occurs in your code, your
program will be executed even though you have some logical errors in
your program, but we won’t get the expected output.
Example: if 10<20:
Print(’20 is the smaller value’)
In python ‘=’ and ‘==’ are used to perform different tasks, ‘=’ is called as
assignment operator and ‘==’ is called as comparison operator.’=’ is used
to assign a value to a variable whereas ‘==’ is used to check whether the
left hand side value and right hand side values are equal or not.
Example:
A=10(assigning a value 10 to the variable ‘A’)
B==10(checking whether the value of B is equal to 10 or not)
Comments are the non-executable statements in python, it won’t affect
the execution of the program. The information what we are giving in the
form of comments is to add the explanation about a statement.in python
we can give 2 types of comments.
1) Single line comments(must be starts with a symbol ‘#’
2) Multiline comments (must be enclosed in ‘’’ ‘’’ triple quotes)
Simple program to perform basic arithmetic operation in python
A=int(input(‘enter the value of A’))
B=int(input(‘enter the value of B’))
C=A+B
Print(‘addition of A and B is’,C)
C=A-B
Print(‘Subtraction of A and B is’,C)
D=A*B
Print(‘Multiplication of A and B is’ ,D)
E=A/B
Print(‘Division of A and B is’,E)
Simple python program to find sum of the marks and percentage of a student
Maths=int(input(‘enter your maths marks(max-100))
science=int(input(‘enter your science marks(max-100))
II lan=int(input(‘enter your 2nd language marks(max-100))
social=int(input(‘enter your social marks(max-100))
english=int(input(‘enter your english marks(max-100))
total=Maths+science+II lan+social+English
percentage=total/500*100
Print(‘total marks secured is’, total)
Print(‘percentage is’,percentage)