Cache memory
script and interactive mode
Number Conversion
Difference between keyword and identfier
Comments in python
Membership operators
(%,// and **) Operators
Conversion of math expression into Python code(using pow(),sqrt(),exp() methods)
Mutable and immutable Data types
range() method
String slices
String Operators( +,*,membership , relational)
Expression and statements
lvalue and rvalue
Algorithm and programs
Flow Chart , symbols and programs
Jumping statements(break and continue)
Errors in python
Type conversion
De morgans law
Empty statement
Programs
Syntax error related questions
Output related questions
WAP to print the Reverse of given string
Find the given string in palindrome or not
Find the factorial of given number
WAP to Print the Fibonacci series
0 1 1 2 3 5 8 13 21 34
Generating triangle patterns
WAP to find the given no is prime or not prime
Cache memory
fast speed memory used between CPU and main memory. It is used to reduce the speed mismatch of both. It increase the performance of CPU
Membership operators:
in and not in are the membership operators in Python. They are used to test whether a value or variable is found in a sequence (string, list, tuple, set and dictionary).
x = 'Hello world'
y = {1:'a',2:'b'}
# Output: True
print('H' in x)
# Output: True
print('hello' not in x)
>1 in y
True
>'a' in y
False
>2 in y
True
>'b' in y
False
>3 in y
False
Type Conversion
Change the data type of a variable from one type to another. There ae two type of Conversion Explicit and Implicit
Explicit (Type Casting) :
Done by the user using predefined functions like int(), float(), str(), bool() etc.
a=10.5
a in float type
if we want to convert it in integer
b=int(a)
Implicit (type promotion))
Performed by the compiler automatically
in a mixed arithmetic expression, lower data type are automatically converted in higher type
x = 10
>type(x)
int
y = 10.6
>type(y))
float
z = x + y
>type(z)
float
type z in automatically promoted in float
another example
a=5
type(a)
<class 'int'>
str(a)
'5'
type(a)
<class 'int'>
do nothing statement / time delay statement/ Empty statement is pass
pass
Comments :
Are ignore by the compiler.
Not executed by the compiler
written using # sign or using triple quotes
#this is single line comment
""" this is
multi line comment"""
Jumping statements(break and continue)
break: It is jumping statement. It is used to break the for or while loop block
for example
for i in range(10):
if(i==5):
print(i)
break
continue: It is jumping statement. It skip current iteration and continue loop for next iteration
example
for i in range(10):
print(i)
if(i==5):
continue
Output of the program will be 1 2 3 4 6 7 8 9
range() Function
The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specified number.
Syntax
range(start, stop, step)
start and step is optional but stop is required. step value is by default 1 and start value is by default 0
e.g
for i in range(1,6):
print(i)
Output 1 2 3 4 5
Statement Output
range(3, 20, 2) 3 5 7 9 11 13 15 17 19
range(5,10) 5,6,7,8,9
range(9,3,-1) 9 8 7 6 5 4
range(10,1,-2) 10 8 6 4 2
range(5) results 0 1 2 3 4
Errors: bugs or fault in program that stop the program or produce incorrect output
Syntax Error:
Grammar mistake done by programmer. appear at compile time, stop the execution of program.
such as colon mistake, indent mistake etc.
such as Type error, Value error, indent error, index out of range error
Logical errors
Logical Errors occur due to wrong program logic. program runs but produce in correct output
avg=a+b/2
give wrong average
correct code (a+b)/2
Runtime Errors:
Occurs while the program is running after being successfully compiled.
Division by Zero.
Modulo Operation by Zero.
Debugging:
Debugging is the process of detecting and removing of existing and potential errors
lvalue : object that come on the left hand side of an assignment.
rvalue : expression that come on the right hand side of an assignment. In python everything is rvalue
a=20
b=30
c=a+b
But you cannot write as
a+b=c
20=a
Algorithm
An Algorithm is a step by step procedure to solve a given problem.
Flow chart :
Pictorial representation of an step by step solution of a problem.
It is helpful to show the flow of execution and explain the program
WAP to Print the Fibonacci series
0 1 1 2 3 5 8 13 21 34
a=0
b=1
print(a)
print(b)
s=a+b
for i in range(8):
print(s)
a=b
b=s
s=a+b
Given no is Prime or not Prime
num =int(input("Enter a number"))
if(num>1):
# prime number is always greater than 1
for i in range(2, int(num/2)+1):
if(num % i ==0):
print(num, "is not a prime number")
break
else:
print(num, "prime number")
else:
print(num, "is not a prime number")
Generating triangle patterns
(1)
1
12
123
1234
12345
s="12345"
p=""
for i in s:
p=p+i
print(p)
(2)
*
**
***
****
*****
s="*****"
p=""
for i in s:
p=p+i
print(p)
#WAP to enter a string and print its reverse
s=input("enter a string")
rev = ""
for i in s:
rev = i + rev
print(rev)
#WAP to enter a string and check it is palindrome or not
s=input("enter a string")
str = ""
for i in s:
str = i + str
if(s==str):
print("Palindrome")
else:
print("Not Palindrome")
Find factorial of given no ? for example factorial of 5 is 5*4*3*2*1=120
n=int(input("Enter number:"))
fact=1
while(n>0):
fact=fact*n
n=n-1
print("Factorial of the number is: ")
print(fact)
Write a program to store rollno and marks of student and serach by rollno
students={}
i=1
while i<=2:
rollno=int(input("Enter rollno"))
marks=int(input("enter marks"))
students[rollno]=marks
i=i+1
print(students)
n=int(input("Enter your rollno"))
for i,k in students.items():
if(i==n):
print(i,k)
Write a program to read the name, rollno and marks of 5 students and search the record on base of rollno
students={ }
r=[ ]
i=1
while i<=2:
name=input("Enter name")
rollno=int(input("Enter rollno"))
marks=int(input("enter marks"))
r.append(rollno)
r.append(marks)
students[name]=r
r=[]
i=i+1
print(students)
n=int(input("Enter your rollno"))
for i,k in students.items():
if(k[0]==n):
print(i,k)
students={}
r=[]
i=1
while i<=2:
rollno=int(input("Enter rollno"))
name=input("Enter name")
marks=int(input("enter marks"))
Hname=input("Enter house name")
mobile=input("Enter mobile name")
address=input("Enter your address
r.append(name)
r.append(marks)
r.append(Hname)
r.append(mobile)
r.append(address)
students[rollno]=r
r=[]
i=i+1
print(students)
n=int(input("Enter your rollno"))
for i,k in students.items():
if(i==n):
print(i,k)
Block diagram of Computer System
units
Memory Units