Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Python

Keywords
Identifier
Naming conventions
Assigning values to variables
Multiple assignment
Datatypes
Datatype conversion – implicit and explicit
Type ()
Operators
Arithmetic
Relational operators
Logical Operators
Shorthand assignment operators
Comments - Two types
Concatenation
Operator Precedence
Evaluating expression
1. 79 – 3 * 4 + 6 // 2
2. (6+1)*5//4+(1+9)/2
3. 4+3*((2*12)-4)/5
Types of Errors
print(7+10
avg = maths+english+ip/3
Number1=10
Number2 =5
Result = (Number1+Number2) / (Number2 -5)
Programs using input function
1. Write a program to accept the principle amount, rate of interest
and time from the user and calculate the simple interest and total
amount.
2. Write a program to accept the marks of 5 subjects. Calculate and
print the total mark and average marks
3.
1. Area and perimeter of rectangle
2. Area and perimeter of Circle
3. Area and perimeter of Square
4. Area and perimeter of Triangle

Area of rectangle – length * breadth


Perimeter of rectangle - 2 (l + b)

Area of Square - Side * Side


Perimeter of Square – 4 * Side

Area of Circle – 3.14 * radius * radius


Perimeter of Circle – 2 * 3.14 * radius

Area of Triangle – ½ * base * height


Perimeter of Triangle – a+b+c

Control statements
Decision making statements/Selection statements
if,if..else,if elif else..
Program to find largest among two numbers
Program to check given number is positive or negative.
Program to check given number is positive, negative or zero.
Program to input the bill amount and calculate the discount as per the
following conditions.

Billamount > 10000 and <= 15000 then 5% discount


Billamount > 15000 and <= 20000 then 7% discount
Billamount > 20000 and <= 25000 then 8% discount
Billamount > 25000 then 10% discount
Else no discount

Error correction Questions


num = int(input(“Enter a number”))
num1= =15
if num = num1:
print( both are equal,num,num1)
else
print(“not equal”)
range() function

Python provides the following types of loops.

For loop - Syntax

While loop - Syntax

Control variable
1. Program to find the factorial of a given number
n=int(input("enter n"))
i=1
fact=1
while(i<=n):
fact=fact*i
i=i+1
print(fact)
2. Program to find the sum of digits of a number
n= int (input("enter anumber"))
sum=0
while(n>0):
a=n%10
sum=sum+a
n=n//10
print(sum)
3. Program to find the reverse of a number
n= int (input("enter anumber"))
sum=0
while(n>0):
a=n%10
sum=sum*10+a
n=n//10
print(sum)
4. Program to check whether given number is Armstrong or not.

n=eval(input("enter a number"))
org=n
sum=0
while(n>0):
a=n%10
sum=sum+a*a*a
n=n//10
if(sum==org):
print("The given number is Armstrong number")
else:
print("The givennumber is not Armstrong number")

What will be the output of the following program ?

i=1
While i<=10:
if i%2==0:
print(i , '#' )
else:
print(i , '%')
i=i+1
How many times the following loop will execute

for i in range(1,10,2):
print(i)
Convert while loop to for loop
i=1
while i<10:
print(i)
i=i+2
Lists
List
Index
Positive, negative index
Slicing
Built functions
Reverse (-1,-2,-3)

You might also like