RN Reddy Python
RN Reddy Python
RN Reddy Python
1.Core Python - 3
2.Adv.Python - 137
3.Interview Questions - 231
4.Logical Programs - 259
.
CORE
PHTHON
.
ADV
PHTHON
.
1. What is PYTHON?
A. PYTHON is a Programming Language.
2. Who introduced python?
A.Gudio Van Rossum introduced python in the year 1989,he was from NetherLands.
1
12. Is Python is compiler based or interpreter based?
A. Python is a interpreter based programming language.
2
21. What are Arithmetic operators?
A. Arithmetic operators are used to perform mathematical operations.
Operator Operation Example
+ Addition 4+2=6
- Subtraction 4-2=2
* Multiplication 4*2=8
/ Division 4/2=2.0
// Floor Division 4//2=2
% Modulation 4%2=0
** Power 4**2=16
3
25. What is membership operators?
A. Membership operators used to check whether given member is existed or not. If existed true is
returned otherwise false is returned.The following are membership operators in python:
1. in
2. not in
• Fundamental Datatypes
• Collection Datatypes
• Other Datatypes
4
30. What are Fundamental Data types?
A. Fundamental datatypes are called as primary datatypes.These datatypes are main datatypes in
python.There are 5 types of Fundamental datatypes they are:
• int
• float
• str
• bool
• complex
37.What is the differences between single quotes , double quotes, triple quotes?
A.Using single quotes(' ') and double quotes(" ") we can represent only single line but using triple
quotes(''' ''') we can represent multiline string.
38.What is the difference between double quotes(" ") and single quotes (' ')?
A.There is no difference but whenever we want to highlight a substring within string we will use sin-
gle quotes for substring and double quotes for full string.
print(a)
5
40.When we will go for bool?
A.Whenever we want to have True or False value.
43.What is typecasting?
A.Converting from one datatype to another datatype is called typecasting.
• int()
• float()
• str()
• bool()
• complex()
45.What is int()?
A.int() method will convert the given value into int type except complex type.
46.What is float()?
A.float() method will convert the given any type value into float except complex type.
47.What is str()?
A.str() method will convert the any given value into str type.
48.What is bool()?
A.bool() method will convert given value into bool type.
49.What is complex()?
A.complex() method will convert the given value into complex type except string.
6
53. When we will go for control statements?
A. Whenever we want to control the program control according to our requirement we will go for
control statements.
7
61. What is the syntax multiple if?
A. if<condition1>:
st1
If<condition2>:
st2
If<condition3>:
st3
8
72. When we will go for if else?
A.Whenever we have two options, among two options if we want to execute one option based on
condition.
9
84. What are the string handling methods in python?
A. The string handling methods are:
• len()
• isupper()
• islower()
• upper()
• lower()
• isalnum()
• capitalize()
• count()
• startswith()
• endswith()
• find()
86.What is isupper()?
A. It will return true if the given string is in upper case, else false.
Ex: str1="rama"
str2="RAMA"
print("str1:",str1.isupper())
print("str2:",str2.isupper())
o/p: str1:false
str2:true
10
89. What is lower()?
A. It will convert the given string into lower case.
Ex: str1="RAMA "
print("str1:",str1.lower())
o/p: str1:rama
11
95. What is find()?
A. It will return the index of the character within the string.
Ex: str1="rama"
print("str1:",str1.find('r'))
o/p: str1:0
96.What is Collection?
A. Collection is representing collection of elements (objects).
12
102. What is tuple?
A.It is a collection of objects. It is represented with parenthesis() and comma to separate values. It is
immutable object. Insertion order is fixed.Nested tuples also can be created.
Empnames=(value1,value2,value3………,value n)
13
109. What is dictionary?
A. Dictionary is a collection of "key : values" pairs. Dictionaries are mutable that means we can do
changes to dictionaries.
Syntax:<dict_name>={key1:value1,key2:value2,………………key n : value n}
14
118. What are the types of arguments/parameters?
A. There are 6 types of arguments, they are:
1. Formal arguments
2. Actual arguments
3. Positional arguments
4. Keyword arguments
5. Default arguments
6. Variable length arguments
15
129. What are the types of modules?
A. Types of modules are:
1. System defined modules
Ex: math, date time, string………..
2. User defined modules
To see the list of system defined modules help("modules")
o/p: It will display all the available system defined modules in python.
16
139.What are oops principles?
A. Every oop language should follow the four principles. They are called oops principles.
• Encapsulation
• Abstraction
• Inheritance
• Polymorphism
17
148. What is an object?
A. An object is a instance of a class. Class is a logical representation object is a physical representa-
tion of a class.
18
159. When we will go for instance variable?
A. Whenever field is required for every object with different value but value can be changed ,we will
declare it as instance variable.
19
167. How to call instance method within the class?
A. We don't require to create object , we can access by using self keyword. Here self is nothing but
current class object.
20
173. What is hybrid inheritance?
A. Combination of any 2 inheritances is called Hybrid inheritance i.e., multilevel, multiple or multi-
ple, multipath is called hybrid inheritance.
Ex: class BC:
//members
class DC(BC):
//members
class TC(BC):
//members
class MC(DC,TC):
//members
21
182. What is method overriding?
A. Implementing super class method within the subclass with the same name and same signature is
called as method overriding.
186.
22
1.Write a Python Program to print message:
Program:
print("hi")
OUTPUT:
print("hi")
print("hello")
OUTPUT:
print("Welcome To Python")
print("Welcome To Programing")
OUTPUT:
4.Write a python Program to store a person information “Rama” into a one variable called
“name” and a person age 20 into a another variable called “age”.Print two values with the
help of variables.
PROGRAM:
name="rama"
age=20
print(name)
print(age)
OUTPUT:
empno=123
empname="rama"
empSal=2000
print("Employee no is :",empno)
OUTPUT:
6.Write a Python program to store three subject marks60,70,80 into three variables they are
M1,M2,M3.Calculate total marks Store into one variable called totMarks and calculate
average marks store into another variable called avgmarks.Print the totalMark and avgmarks
with the help of message and variable.
PROGRAM:
m1=float(input("enter m1 marks:"))
m2=float(input("enter m2 marks:"))
m3=float(input("enter m3 marks:"))
totmarks=m1+m2+m3
avgmarks=totmarks/6
p1=1000
p2=2000
totbill=p1+p2
disc=totbill*0.10
totbill=totbill-disc
OUTPUT:
8.Write a python program to store two product cost i.e 1000,2000 into two variables they are
P1,P2.Calculate total bill store into one variable called totbill .On total bill 20% discount and
store discount in disc variable .After discount calculate 30% tax on total bill.Display the total
bill by using message and variable.
PROGRAM:
p1=1000
p1disc=p1*0.10
p1=p1-p1disc
p1tax=p1*0.20
p1=p1+p1tax
p2=2000
p2disc=p2*0.20
p2=p2-p2disc
p2tax=p2*0.30
p2=p2+p2tax
totbill=p1+p2
tax=totbill*0.30
PROGRAM:
p1=float(input("Enter p1 cost:"))
p2=float(input("Enter p2 cost:"))
p1disc=p1*0.10
p1=p1-p1disc
p1tax=p1*0.20
p1=p1+p1tax
p2disc=p1*0.20
p2=p2-p2disc
p2tax=p2*0.20
p2=p2+p2tax
totbill=p1+p2
print("totbill is:",totbill)
OUTPUT:
10.Write a python program to accept two number from the users store into a variable a and b
and perform addition.Display addition result.
PROGRAM:
c=int(a)+int(b)
OUTPUT
11. Write a python program to accept two product cost P1,P2 .Calculate total bill .On total bill
10% discount.Display the total bill after discount.
PROGRAM:
p1=float(input("Enter p1 cost:"))
p2=float(input("Enter p2 cost:"))
##p3=float(input("Enter p3 cost:"))+p3
totbill=p1+p2
disc=totbill*0.10
totbill=totbill-disc
OUTPUT:
13.Write a python program to accept two product cost P1,P2.On P1 10% discount and on P2
20% discount .Calculate total bill.On total bill 30% tax .Display P1,P2 cost after discount and
display tax .Finally display total bill after tax.
PROGRAM:
p1=float(input("Enter p1 cost:"))
p2=float(input("Enter p2 cost:"))
p1disc=p1*0.10
p1=p1-p1disc
p2disc=p1*0.20
p2=p2-p2disc
totbill=p1+p2
tax=totbill*0.30
print("tax is",tax)
totbill=totbill+tax
print("totbill is:",totbill)
OUTPUT:
14.Write a python Program to accept two numbers and perform division and display division
result.
PROGRAM:
c=int(a)/int(b)
OUTPUT:
15.Write a python Program to accept two numbers and perform substraction and display
substraction result.
PROGRAM:
c=int(a)-int(b)
OUTPUT:
16.Write a python Program to accept two numbers and perform multiplication & division and
display result.
PROGRAM:
c=a/b
c=a*b
OUTPUT:
17.Divide by zero.
PROGRAM:
while b==0:
c=a/b
OUTPUT:
Program:
i=int(input("Enter i value"))
j=int(input("enter j value"))
if i>j:
print("i is greater than j")
else:
print("j is grater than i")
OUTPUT:
19. Write a python program to compare i and j value by using if elif else.
PROGRAM:
i=int(input("Enter i value"))
j=int(input("enter j value"))
if i>j:
elif j<i:
else:
OUTPUT:
20.Write a python program to accept age from the user and display user status:
i)age>=58:senior citizen
vi)Invalid age
PROGRAM:
if age>=58:
print("senior citizen")
print("working citizen")
print("college student")
print("school kid")
print("playing kid")
else:
print("invalid age")
OUTPUT:
21.Write a python program to accept a number from 0 to 9 print in letters.
PROGRAM:
if number==0:
print("zero")
elif number==1:
print("one")
elif number==2:
print("two")
elif number==3:
print("three")
elif number==4:
print("four")
elif number==5:
print("five")
elif number==6:
print("six")
elif number==7:
print("seven")
elif number==8:
print("eight")
elif number==9:
print("nine")
else:
print("invalid input.....")
OUTPUT:
22.Write a python program to accept three subject marks i.eM1,M2,M3.Calculate total marks
store into a variable called totmarks and calculate average marks store into another variable
avgmarks and display the result:
i)if he got less than 35 marks in any one subject ,student is fail.
M1=int(input("Enter M1 marks:"))
M2=int(input("Enter M2 marks:"))
totmarks=M1+M2+M3
avgMarks=totmarks/3
print("Result is fail")
if avgMarks>60:
elif avgMarks>50:
elif avgMarks>35:
OUTPUT:
23. Implement comparing I and j by using nested if conditions.
PROGRAM:
i = int(input("Enter i value:"))
j = int(input("Enter j value:"))
if i>j:
else:
if i<j:
else:
OUTPUT:
24.Write a python program to print upto given range by using for loop.
PROGRAM
i=int(input("Enter ur range:"))
for i in range(1,i+1):
print(i)
OUTPUT:
for i in range(5,0,-1):
print(i)
#OUTPUT:
26. Write a python program to print odd number from 1to 10 by using for loop.
PROGRAM:
for i in range(1,10):
if i%2!=0:
print(i)
OUTPUT:
Expected output:
10
20
30
40
50
PROGRAM:
for i in range(10,60,10):
print(i)
OUTPUT:
28. Write a python program to print even numbers in reverse by using for loop.
Expected output:
10
8
6
4
2
PROGRAM:
for i in range(10,0,-1):
if i%2==0:
print(i)
OUTPUT
Expected Output:
1 2 3 4 5
PROGRAM:
print(i,end=" ")
OUTPUT:
Expected output: 1
3
5
7
9
PROGRAM:
i=1
while i<=9:
print(i)
i=i+2
OUTPUT:
31. Write a python program to print like below by using while loop:
Expected output: 10
8
6
4
2
PROGRAM:
i=10
while i>0:
print(i)
i=i-2
OUTPUT:
32. Write a python program to print like below by using while loop:
Expected output: 1
2
3
4
5
6 7 8 9 10
PROGRAM:
i=1
while i<=6:
print(i)
i=i+1
while i<=10:
print(i,end=' ')
i=i+1
OUTPUT:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
PROGRAM:
for i in range(1,5+1):
for j in range(1,i+1):
print(j,end=" ")
print(" ")
OUTPUT:
Expected output:
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
PROGRAM:
for i in range(5,0,-1):
for j in range(i,0,-1):
print(j,end=" ")
print(" ")
OUTPUT:
1
2 3
4 5 6
7 8 9 10
PROGRAM:
a=1
for i in range(1,5):
for j in range(1,i+1):
print(a,end=" ")
a=a+1
print()
OUTPUT:
40. Write a python program to print like below:
Expected output:
1 2 3 4 5
2 3 4 5
3 4 5
4 5
5
PROGRAM:
for i in range(1,6):
for j in range(i,6):
print(j,end=" ")
print("")
OUTPUT:
41. Write a python program to print like below by using while loop:
Expected output:
1234
567
89
10
PROGRAM:
a=1
for i in range(1,5):
for j in range(1,i+1):
print(a,end=" ")
a=a+1
print()
OUTPUT:
43. Write a python program to print like below by using while loop:
Expected output:
12345
1234
123
12
1
PROGRAM:
i=5
while i>=1:
j=1
while j<=i:
print(j,end='')
j=j+1
print()
i=i-1
OUTPUT:
44. Write a python program to accept a string print in reverse :
PROGRAM
str1= input("Enter your string:")
str1[::-1]
OUTPUT:
PROGRAM
a=0
b=1
c=0
while a<n:
c=a+b
print(a,end='')
a=b
b=c
OUTPUT:
46.Write a python program to display list ,sum & number of even numbers up to given range.
PROGRAM:
n=int(input("Enter range:"))
evensum=0
evencount=0
if i%2==0:
evensum+=i
evencount+=1
print(i)
OUTPUT:
47. Write a python program to display list ,sum & number of odd numbers up to given range.
PROGRAM:
n=int(input("Enter range:"))
oddsum=0
evencount=0
if i%2!=0:
oddsum+=i
evencount+=1
print(i)
OUTPUT:
48.Write a python program to accept a number check is it prime or not.
PROGRAM:
ctr=0
for i in range(2,n):
if(n%i==0):
ctr=ctr+1
if(ctr==0):
else:
OUTPUT:
49. Write a python program to display list of prime number ,sum of prime number & number
of prime numbers up to given range.
PROGRAM:
s=0
c=0
for m in range(1,n+1):
x=int(m/2)
ctr=1
for i in range(1,x+1):
if(m%i==0):
ctr=ctr+1
if(ctr==2):
print(m)
s=s+m
c=c+1
OUTPUT:
50.Write a python program to accept a number and print in reverse.
PROGRAM:
rev=0
while(n>0):
a=n%10
rev=rev*10+a
n=n//10
OUTPUT:
PROGRAM:
str1[::-1]
OUTPUT:
52.Write a python program to accept a string and check is it palidrom or not.
PROGRAM:
x=n[::-1]
if x==n:
print("It is palindrome")
else:
OUTPUT:
PROGRAM:
x=n[::-1]
if x==n:
print("It is palindrome")
else:
PROGRAM:
a=int(input("Enter a value:"))
b=int(input("Enter b value:"))
a,b=b,a
OUTPUT:
55.Write a python program to accept a string and print length of string.
Expected Output:
PROGRAM:
OUTPUT:
Expected Output:
Sum:6
PROGRAM:
rev=0
rem=0
while(i!=0):
rem=i%10
rev=rev+rem
i=i//10
OUTPUT:
#LIST PROGRAM:
Expected Output:[10,20,30,40,50]
PROGRAM:
list1=[10,20,30,40,50]
print(list1)
OUTPUT:
Expected Output:
10
20
30
40
50
PROGRAM:
list1=[10,20,30,40,50]
for i in list1:
print(i)
OUTPUT:
59.Printing the list of element in reverse.
Expected Output:[50,40,30,20,10]
PROGRAM:
list1=[10,20,30,40,50]
print(list1[::-1])
OUPTPUT:
60.Accepting the number from the users & appending the list.
Program:
mylist=[]
for i in range(1,6):
j=int(input("Enter a number:"))
mylist.append(j)
for i in mylist:
print(i,end=" ")
OUTPUT:
61.Write a python program to perform operation on list by using list method.
Program:
mylist.append(60)
print(mylist)
#insert()
mylist.insert(3,70)
print(mylist)
#extend()
mylist.extend([80,90,100,110])
#range()
mylist[4:4]=range(31,36)
print(mylist)
#remove()
mylist.remove(10)
#pop()
mylist.pop()
#del()
del(mylist[1:3])
#reverse()
mylist.reverse()
#sort()
mylist.sort()
#copy()
list2=mylist.copy()
OUTPUT:
PROGRAM:
Empnos=(10,20,30,40,50)
print(Empnos)
OUTPUT:
63. Write a python program to perform operation on tuple by using tuple method.
PROGRAM:
#tuple()
mylist=[10,20,30,40,50,50,50]
mytuple=tuple(mylist)
print(mytuple)
#count()
print("50 appears",mylist.count(50),"times")
#index()
#eval()
print(mytuple1)
OUTPUT:
64.Write a python program to perform various operation on set collection with buit in
methods.
PROGRAM:
#set()
mylist1={10,20,30,40}
myset=set(mylist1)
#copy()
mylatestset=myset.copy()
#Uions of set
mylist2={10,20,50,60,70}
set3=mylist1.union(mylist2)
#intersection of set
set4=mylist1.intersection(mylist2)
print("intersection elements are:",set4)
OUTPUT:
65.Write a python program to perform various operation on frozenset collection with buit in
methods.
PROGRAM:
#set()
mylist1={10,20,30,40}
myset=set(mylist1)
#copy()
mylatestset=myset.copy()
#Uions of set
mylist2={10,20,50,60,70}
set3=mylist1.union(mylist2)
#intersection of set
set4=mylist1.intersection(mylist2)
66.Write a python program to perform various operation on Dictionary collection with buit in
methods.
PROGRAM:
fruitdict={111:'apple',222:'Banana',333:'chery'}
print(fruitdict)
#len()
print("length is:",(len(fruitdict)))
#keys
print("key is:",fruitdict.keys())
#values()
print("value is:",fruitdict.values())
#copy()
mydict=fruitdict.copy()
OUTPUT:
67.Writw a python program for function with parameter and with return value.
PROGRAM:
def Add(a,b):
c=a+b
return c
res=Add(x,y)
OUTPUT:
68.Writw a python program for function with parameter and without returning value.
PROGRAM:
def Sub(x,y):
z=x-y
Sub(a,b)
OUTPUT:
69.Writw a python program for function without parameter and with return value.
PROGRAM:
def GenerateEmpNo():
return 111
empno=GenerateEmpNo()
OUTPUT:
70.Writw a python program for function without parameter and not returning any value.
PROGRAM:
def Greet():
print("Good Morning")
#calling Function
Greet()
OUTPUT:
71.Writw a python program for returing multiple values from a function.
PROGRAM:
def Multiplication(a,b):
c=a+b
d=a-b
e=a*b
h=a%b
return c,d,e,f,g,h
res=Multiplication(num1,num2)
OUTPUT:
72.Write a python program to create user defined module.
PROGRAM:
def Add(a,b):
print("Sum=",a+b)
def Sub(a,b):
print("Substraction=",a-b)
def Mul(a,b):
print("Multiplication=",a*b)
def Div(a,b):
print("Division=",a/b)
import Calc
Calc.Add(i,j)
Calc.Sub(i,j)
Calc.Mul(i,j)
Calc.Div(i,j)
Save as”MYclient.py”
OUTPUT:
73.Write a puython program for package.
PROGRAM:
def addition(a,b):
return a+b
def substraction(a,b):
return a-b
def Multiplication(a,b):
return a*b
def Division(a,b):
return a/b
def Modulation(a,b):
return a%b
//save as”ao.module.py”
def string_length(string1):
return len(string1)
def string_reverse(string):
return string[::-1]
import ao_module as a
import string_module as s
print("adition=",a.addition(i,j))
print("substraction=",a.substraction(i,j))
print("Multiplication=",a.Multiplication(i,j))
print("Division=",a.Division(i,j))
print("Modulation=",a.Modulation(i,j))
print("*"*40)
string1=input("Entera string:")
OUTPUT:
74.Write a python program to define a lambda function to find square of even numbers.
PROGRAM:
square=lambda n:n*n
print("Square of 4 is:",square(4))
print("Square of 2 is:",square(2))
OUTPUT:
75. Write a python program to find the sum of two given numbers.
PROGRAM:
sum=lambda a,b:a+b
OUTPUT:
76. Write a python program to find the square of given numbers.
PROGRAM:
list1=[100,200,300,400,500]
list2=list(map(lambda x:x*x,list1))
print(list2)
OUTPUT:
77.Write apython program to filter the list element by using Lambda functions.
PROGRAM:
list1=[10,20,30,40,50,60,70,80,90,100]
even=list(filter(lambda x:x%2==0,list1))
print(even)
OUTPUT: