String
x ='i LoVe pYtHoN PrOGrAm'
Q1.write a code to get the following ouput....
output-: 'I love python program'
Q2.write a code to get the following ouput....
output-: 'I Love Python Program'
Q3.write a code to get the following ouput....
output-: 'i love python program'
Q4.write a code to get the following ouput....
output-: 'I LOVE PYTHON PROGRAM'
Q5.write a code to get the following ouput....
output-: ['i', 'LoVe', 'pYtHoN', 'PrOGrAm']
Q6.use format method to inject the following name and age
variable in given variable named string
name="python"
age=30
string="my name is {} and my age is {}"
output-: 'my name is python and my age is 30'
Q7.write a code to retrieve the word 'pYtHoN' by using slicing
from variable x
output-: 'pYtHoN'
Tuple
t = (2,1,4,6,2,1,4,1,2,7,1)
Q1.write the code to count the frequency of 1
Q2.write a code to merge tuple t with (11,12,13,14) & store in
variable named newt
#List
x = [2,4,6,8,10]
Q1.write a code to add a element 'eleven' , inside list at the end
output-:[2,4,6,8,10,'eleven']
Q2.perform an operation to get the following output
output-: ['one', 2, 4, 6, 8, 10, 'eleven']
Q3.perform an operation to merge the list y inside list x
y= [12,13,14]
output-: ['one', 2, 4, 6, 8, 10, 'eleven', 12, 13, 14]
Q4.perform an operation to get the following output
output-: [14, 13, 12, 'eleven', 10, 8, 6, 4, 2, 'one']
Q5.Perform one single operation to remove 'eleven', 10, 8 all
together at once
output-: [14, 13, 12, 6, 4, 2, 'one']
Q6.write a code to remove 'one' element from the list
output-: [14, 13, 12, 6, 4, 2]
Q7.write a code to get the following output
x = ["hey","there","hello","world"]
y= " "
output-: 'hey there hello world'
#Dictionary
d = {'a':10,'b':30,'c':50,'d':100}
Q1.write a code to update the value of key 'b' to 300
output-: {'a':10,'b':300,'c':50,'d':100}
Q2.write a code to check if key 'e' is present in dictionary d
if it 'e' is not present in d, then it should return 'e key does not
exist'
output-: 'e key does not exist'
Q3.write a code to add new key,value i.e 'e',600 respectively
inside dictionary d
output-: {'a':10,'b':300,'c':50,'d':100,'e':600}
Q4.write a code to display all the values from the dictionary
output-: dict_values([10, 300, 50, 100, 600])
Q5.write a code to merge the dictionary x inside dictionry d
x = {'i':11,'j':12,'k':13,'l':14}
output-: {'a':10,'b':300,'c':50,'d':100,'e':600,'i':11,'j':12,'k':13,'l':14}
Q6.write a code to remove the key 'j' from dictionary d
output-: {'a':10,'b':300,'c':50,'d':100,'e':600,'i':11,'k':13,'l':14}
Set
a = {1,2,3,4,5}
b = {3,4,5,6,7,8,9}
Q1. Write a code to perform union operation on a and b set
Q2. Write a code to perform intersection operation on set a and b
Q3. Write a code to add 6, in set a
Operators
Area of triangle (0.5*b*h)
vol of sphere(4/3)*3.14*(r**3)
Swap the variable x=10,y=5
o/p -: x is 5 & y is 10
WAP which takes two numbers as input and it should calculate & display all the arithmetic
operation
Flow Control
WAP which takes an arithmetic operators & 2 numbers, as an and do the calculation based on the
input operator
WAP to calculate area of triangle --> 0.5*b*h
WAP to calculate vol of sphere --> (4/3)*3.14*(r**3)
WAP for check a number is leap year or not by using following constraints-:
Constraints-:
1. N div by 400 --> leap year
2. N div by 4 , N not div by 100 --> leap year
WAP to display the grade given a mark by using following constraint-:
Constraints -:
75 & above -: A grade
60-74 -: B grade
35-59 -: C grade
Below 35 -: Fail
WAP to check weather the number is even or odd
Constraints-:
N div by 2 → even
LOOPs
WAP to print 1-10 using for loop
WAP to print 10-1 using for loop
WAP to print nth fibonacci series
WAP to calculate the factorial of number using for loop
WAP to add 1st nth natural using for loop
WAP to print the table of given N using for loop
WAP to print 1-10 using while loop
WAP to print 10-1 using while loop
WAP to calculate factorial of given input n using while loop
WAP to print the sum of 1st nth natural numbers using while loop
WAP to print fibonacci series till nth input value using while loop
WAP to print the table of given N using while loop
WAP to list out all the leap years from 1900-2030 using for loop
WAP to give all the even and odd number in list from 1-100 using for loop
wap to reverse a number
input -: 7546
ouput -: 6457
WAP to check whether the given number is palindrome or not
WAP to check whether the given number is armstrong or not
WAP to check whether the given number is Strong or not
WAP to check whether the given number is Neon or not
WAP to check whether the given number is perfect or not
WAP to perform linear Search
Wap to perform Binary Search
Wap to perform BubbleSort
Wap to perform MergeSort
List comprehension
using list comprehension store all the even numbers from 1 to 100 in a list
using list comprehension store all Leap year from 1900 to 2030 in a list
using list comprehension, store cubes of natural number from 1-20 in a list
library =
[('book1',2002),('book2',2012),('book3',2007),('book4',2015),('book5',2005),('book6',2018)]
Given a list lib, using list comprehension store all the books that was published after 2010
grammar = ['is','not','am','are','do','did','no','will','never','shall','none','was','nor']
Given a list grammar, using list comprehension, filter all the negative words that starts with 'n'
x= [1,2,3]
y=['a','b','c']
Given two list x and, using list comprehension take the cross product of x and y-:
output-:
[(1, 'a'), (1, 'b'), (1, 'c'), (2, 'a'), (2, 'b'), (2, 'c'), (3, 'a'), (3, 'b'), (3, 'c')]
print the following start parttern-:
start parttern 1
**
***
****
start parttern 2
****
***
**
start parttern 3
**
***
****
***
**
Functions
Create a function to calculate the the area of triangle
Create a function that calculates the the volume of sphere
Explain what is default and required arguments with an example of each.
Explain what is variable length arguments i.e *args & **kwargs with an example of each
WAP to create function of prime no
WAP to create a function of perfect number
WAP to create a function of neon number
Explain what is lambda function with the help of example
WAP for factorial using recurrsion
WAP for fibonacci series using recurrsion using one of the memoization technique
Q.Item with highest value count
items = [{'apple': 5}, {'banana': 8}, {'orange': 7}, {'grapes': 4}]
def itemWithHighestValue(items):
pass
Create a lambda function to sort the name list according to their surname.
name = ["jay A kumar",'deepak N sharma','rohit N yadav','mithilesh singh','payal vasave','Fahad
Momin']
o/p-:
['jay A kumar', 'Fahad Momin', 'deepak N sharma', 'mithilesh singh', 'payal vasave', 'rohit N
yadav']
using map function, create a lambda expression to convert the degree celcius to fahrenheit
temp = [('kashmir',1),('mumbai',16),('goa',22),('channai',18),('kerla',20)]
Formula to convert fahrenheit to celsius, f = 9/5 x c + 32
o/p-:
[('kashmir', 33.8), ('mumbai', 60.8), ('goa', 71.6), ('channai', 64.4), ('kerla', 68.0)]
1. Give example of zip(), abs(), round(),pow() function
2. mylist = [11,14,5,78,45,67,9,88,10,303]
a) apply filter to create a list of palindrome numbers from mylist
b) apply filter to create a list of numbers divisible by 3 or 5 from the mylist
3. WAP to find maximum number from the list without using function and slicing or sorting
function
4. WAP to find Minimum number from the list without using function and slicing or sorting
function
5. WAP to get second highest value from the list without using sort function
6. WAP to get second lowest value from the list without using sort function
Module
1.WAP to demonstrate all the methods in datetime module
-> datetime
- year
- month
- day
- timedelta
- strftime
- datetime.strptime
-> time
- hour
- minute
- second
2.Explain the following methods in maths module with an example
- sqrt
-pow
-factorial
-floor
-ceil
-pi
3.Explain the following methods in statistics module with an example
- mean
- median
- mode
- variance
OOP
1.what is oops give 5 Programming language names?
2.Explain 6 Oops concepts
a.class
b.object
c.encapsulation
d.inheritance
e.polimorphism
f.data abstraction
WAP to show various inheritance in python
WAP to show operator overloading in python
WAP to show method overriding in python
What is Constructor and write 4 features of constructor
Write about the following built-in attributes in OOP
a.__dict__
b.__doc__
c.__name__
d.__module__
e.__bases__
Explain all the following function in brief
a.__init__(self) (ie.constructo).
b.__str__(self) method
c.__del__(self) (ie.destructor)
OOP Project 1
Create a class name it as Character, and use following methods and attribute.
-> create a constructor which can initialise the name of character
-> create a two private attributes name it as life and score
-> set life = 3 and score = 0
-> create a methods name it as kicked, punched, stabbed which does the following
action
- when kicked is called, it should increment the score atrribute by 10
- when punched is called, it should increment the score attribute by 5
- when stabbed is called, it should decrement the life attribute by 1
-> create two more method name it as, displaylife and displayscore which does the
follwoing action
- when displaylife is called, it return current life attribute value
- when displayscore is called, it return current score attribute value
Perform the following operations with Character class
-> create 1 object for Character class and initialise the name as Mario
-> call the kicked method
-> call the stabbed method
-> call punched method
-> call stabbed method
OOP project 2
#create a class user
#- create a attribute that can count the number of object created with user class
#- initialise the class with three attributes name, gender, salary
#- create a method showdetails() which should print the name, gender, salary and unique
account no for the user
#create a class bank
#- create a private class variable and name it as balance
#- initialise the class with three attributes name, gender and salary
#- create a method deposite() which has amount parameter,
#it should add the given amount in balance variable
#- create a method withdraw(), which has amount paramter,
#and uses the following constraints to withdraw money
#1. withdraw > balance, it should return insuffient balance and display the current
balance
#2. withdraw >= 100 and withdraw <=balance , it should return Thank you for visiting
#and minus the withdraw amount from balance
#and display the current balance
#3. withdraw < 100, it should return you cannot withdraw less then 100 and display the
current balance
#- create a method, viewbalance(), which will show the account details and balance
#- create a method, transfer(), which has two parameters amt, user
#- the specified amount should be transfered to mentioned user account
#- it should also minus the amount from balance and add the amount to mentioned users
acount
#- amount transfer should be done by using following contraints
#1. amt > balance, it should return insuffient balance and display the current balance
#2. amt >= 1 and withdraw <=balance , it should return amt transfered successfully
#and minus the withdraw amount from balance & add the amt to specified user
account
#and display the current balance
#3. amt < 1, it should return you cannot transfer less then 1 and display the current
balance
Create some test cases to check the system.
Exception Handling
WAP to multiple except in one try with proper comments and notes
WAP to explain else statement proper comments with notes
Write a note on Finally keyword and explain it with the help of program
WAP to explain raise keyword proper comments with notes.
File Handling
1.Write a function in python to count the number of lines from a text file "story.txt" which is not
starting with an alphabet "T".
Example:
If the file "story.txt" contains the following lines:
A boy is playing there.
There is a playground.
An aeroplane is in the sky.
The sky is pink.
Alphabets and numbers are allowed in the password.
The function should display the output as 3
2. Write a function display_words() in python to read lines from a text file "story.txt", and display
those words, which are less than 4 characters.
3.Write a function in Python to copy the content of stroy.txt into story2.txt file.
.