Problem Solving Using Python Programming Lab Manual

Expertise of MRCET have researched and collected B.Tech 1st Year Problem Solving Using Python Programming Lab Manual study material in pdf format. This pdf formatted MRCET B.Tech 1st Year Problem Solving Using Python Programming Lab Manual covered the subject concepts in a comprehend manner for easy reference to their students.  

University

MRCET
Academic year: 2023
Preview text

asd asd asd PROGRAM OUTCOMES A B.Tech –graduate should possess the following program outcomes.

1 Engineering knowledge : Apply the knowledge of mathematics, science, engineering fundamentals and an engineering specialization to the solution of complex engineering problem s.

2 Problem analysis : Identify ,formulate, review research literature, and analyze complex engineering problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and engineering sciences.

3 Design/development of solut ions : Design solutions for complex engineering problems and design system components or processes that meet the specified needs with appropriate consideration for the public health and safety, and the cultural, societal, and environmental considerations.

4 Conduct investigations of complex problems : Use research -based knowledge and research methods including design of experiments, analysis and interpretation of data, and synthesis of the information to provide valid conclusions.

5 Modern tool usage : Create, sel ect, and apply appropriate techniques, resources, and modern engineering and IT tools including prediction and modeling to complex engineering activities with an understanding of the limitations.

6 The engineer and society: Apply reasoning informed by the co ntextual knowledge to assess societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional engineering practice.

7 Environment and sustainability : Understand the impact of the professional engineering solutions in societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable development.

8 Ethics : Apply ethical principles and commit to professional ethics and responsibilities and norms of the engineering practice.

9 Individua l and teamwork : Function effectively as an individual, and as a member or leader in diverse teams ,and in multi disciplinary settings.

10 Communication : Communicate effectively on complex engineering activities with the engineering community and with society at large ,such as, being able to comprehend and write effective reports and design documentation ,make effective presentations ,and give and receive clear instructions.

11 Project management and finance : Demonstrate knowledge and understanding of the engineer ing and management principles and apply these to one’s own work, as a member and leader in a team, to manage projects and in multi disciplinary environments.

12 Lifelong learning : Recognize the need for and have the preparation and ability to engage in ind ependent and life -long learning in the broadest context of technological change.

MALLA REDDY COLLEGE OF ENGINEERING AND TECHNOLOGY I Year B. Tech -I Sem L/ T/P/C -/ - /3/1.5 (R22A0 581 ) PROBLEM SOLVING USING PYTHON PROGRAMMING LAB PROGR AM OBJECTIVES:

1. Able to understan d Syntax and Semantics and create Arrays and Functions in Python.

2. Able to learn d ifferent data types Lists, Dictionaries in Python.

3. Able to know how to execute the programs using loops and control statements .

4. Able to learn decision Making and Functions in Python .

5. Able to know how to handle Files and exception s in Python .

Week 1:

A) Write python program to print Hello World B) Write a python progra m to get string, int, float input from user C) Write a python program to add 2 numbers Week 2:

A) Create a list and perform the following methods 1) insert() 2) remove() 3) append() 4) len() 5) pop() 6) clear() B) Write a python program to find the length of list?

C) Write a python program to find the smallest and largest number in the list?

Week 3:

A) Create a tuple and perform the following methods 1) Add items 2) len() 3) check for item in tuple 4)Access iems B) Write a python program using the following methods: 1) count 2) index C) Write a python program using “+” and “*” operations which resulting a new tuple?

Week 4:

A) Create a dicti onary and apply the following methods 1) Print the dictionary items 2) access items 3) use get() 4)change values 5) use len() B) Write a python code to convert list of tuples into dictionaries?

C) Write python program to store data in list, tuple, set, dictionary and then try to print them.

Week 5:

A) Write a python program to perform arithmetic, assig nment, logical and comparison operators?

B) Write a Python program to add two positive integers without using the '+' operator. (use bitwise operator) C) Write a Python program to perform the basic four operators (+, -, *, /) Week 6:

A) Write a simple python progra m to declare a variable in different possible ways?

B) Write a python program to show precedence of operators using the express ion: z = (v+w) * x / y C) Write a python program to check whether the values of a list exist or not (use membership operator) and also perform identity operation?

Week 7:

A) Write a python program to print a number is positive/negative using if -else.

B) Write a python program to find largest number among thre e numbe rs.

C) Write a python Program to read a number and display corresponding day using if_elif_else?

D) Write a python program to print list of numbers using range and for loop Week 8:

A) Write a python code to print the sum of natural numbe rs using while loop?

B) Write a python prog ram to print the factorial of given number?

C) Write a python program to find the sum of all numbers stored in a list using for loop ?

Week 9 :

A) Using a numpy module create an array and check the following:

1. Type of array 2. Axes of ar ray 3. S hape of arra y 4. Type of elements in array B) Using a numpy module create array and check the following:

1. List with type float 2. 3*4 arr ay with all zeros 3. From t uple 4. Random values Week 10:

A) Write python program in which a function is defined and calling that function prints Hello World .

B) Write python program in which a function ( with single string parameter ) is defined and calling that function prints the string parameters given to function.

C) Write a python program using with any one of pyth on funct ion argument .

Week 11:

A) Write a program to double a given number and add two numbers using lambda().

B) Write a program for filter() to filter on ly even numbers from a given list.

C) Write a program for map() function to double all the items in the list?

D) Write a program to find sum of the numbers for the elements of the list by using reduce().

Week 12:

A) Write a python program to open and write “hello world” into a file.

B) Write a python program to write the conten t “hi python programmin g” for the existing file.

C) Write a python program to read the content of a file.

Week 13 :

A) Write a python program to append data to an existing file and then displayi ng the entire file.

B) Write a python program to open a n ew file, add some data into it a nd display the contents of t hat file.

Week 14 :

A) Write a python program to handle the ZeroDivisonError exception.

B) Write a python program to demonstrate mult iple except block with a single try block .

TEXT BOOKS:

1. R. Nageswara Rao, “Core Python Progra mming”, dream tech 2. Allen B. Downey , “ Think Python: How to Think Like a Computer Scientist”, Second Edition, Updated for Python 3, Shroff/O’Reilly Publi shers, 2016.

PROGRAM OUTCOMES:

After completion of the cour se, Students will be able to:

1. Evaluate Probl em solving and programming capability .

2. Describe the Numbers, Math functions, Strings, List, Tuples and Dictionaries in Python .

3. Implement conditional and loop for python programs .

4. Express different Decision Making statements , Arrays and Functions .

5. Understand and summar ize different File handling operations and exceptions .

CONTENTS Week - No S.No/ Program No List of Programs

1 1 A) Write pytho n program to print Hello World 2 B) Write a python program to get string, int, float input from user 3 C) Write a python program to add 2 numbers 2 1 A) Create a list and perform the following methods 1) insert() 2) remove() 3) append() 4) pop() 5) clear( )

2 B) Write a python program to find the length of list?

3 C) Write a python program to find the smallest and largest number in the list?

3 1 A) Create a tuple and perform the following methods 1) Access items 2) len() 3) check for item in tuple 4)Add i tem 2 B) Write a python program using the follo wing methods:

1) count 2)index 3 C) Write a python program using “+” and “*” operations which resulting a new tuple?

4 1 A) Create a dictionary and apply the follo wing methods, 1) Print the dictionary items 2) acce ss items 3) use get() 4)change values 5)use len() 2 B) Write a pyth on code to convert list of tuples into dictionaries?

3 C) Write python program to store data in list, tuple, set, dictionary and then try to print them.

5 1 A)Write a python program to perform arithmetic, assignment, logical and comparison operators?

2 B) Write a Python program to add two positive integers without using the '+' operator. (use bitwise operator) 3 C) Write a Python prog ram to perform the basic four operators (+, -, *, /) 6 1 A) Write a simple python program to declare a variable in different

possible ways?

2 B) Write a python program to show precedence of operators using the expression: z = (v+w) * x / y 3 C) Write a python program to check whether the values of a list exist or not (use membership operat or) and also perform identity operation?.

7 1 A) Write a Python progr am to print a number is positi ve/nega tive using if -else 2 B) Write a Python progr am to find la rgest number a mong th ree n umbers 3 C) Write a python Program to read a number and display corresp onding day using if_eli f_else ?

4 D) Write a python program to print list of numbers using range and for loop 8 1 A) Write a python code to print the sum of natural numbers using while loop?

2 B) Write a python program to print the factorial of given number?

3 C) Write a python program to find the sum of all numbers stored in alist using for loop?

9 1 A) Using a numpy module create an array and check the following:

1. Type of array 2. Axes of array 3. Shape of arra y 4. Type of elements i n array 2 B) Usin g a numpy module create array and check the following:

1. List with type float 2. 3*4 array with all zeros 3. From t uple 4. Random values 10 1 A) Write python program in which an function is defined and calling that functio n prints Hello World 2 B) Write python program in which an function (with single string

parameter) is defined and calling that function prints the string paramet ers given to function.

3 C) Write a python program using with any one of python function argument?

11 1 A) Write a program to double a given number and add two numbers using lambda()?

2 B) Write a program for filter() to filter only even numbers from a given list.

3 C) Write a program for map() function to double all the items in the list?

4 D) Write a program to find sum of the numbers for the elements of the list by usin g reduce()?

12 1 A) Write a python program to open and write “hello worl d” into a file?

2 B) Write a python code to demonstrate exception hand ling?

3 C) Write a python progra m to write the content “hi python programming” for the existing file.

4 D) Write a python program to concatenate two files into third file?

13 1 A) Write a python program to append data to an existing file and t hen displaying the e ntire file.

2 B) Write a python program to open a new file, add some data into it a nd display the contents of t hat file.

14 1 A) Write a python program to han dle the ZeroDivisonError exception.

2 B) Write a python program to demons trate multiple excep t block with a single try block .

INSTRUCTIONS TO STUDENTS 1. Students should bring lab Manual/Record for every laboratory session and should enter the reading s /observations in the manual while performing the experiment.

2. The group - wise division made in the beginning should be adhered to, and no mix up of students among different groups will be permitted later.

3. The components required pertaining to the experime nt should be collected from stores in –charge after duly filling in the requisition form.

4. When the experiment is completed, students should disconnect the setup made by them, and should return all the components/instruments taken for the purpose.

5. Any damag e to the apparatus that occurs during the experiment should be brought to t he notice of lab in -charge, consequently, the cost of repair or new apparatus should be brought by the students.

6. After completion of the experiment, certification of the concerned s taff in –charge in the observation book is necessary.

7. Students should be present in the labs for the total scheduled duration.

8. Students should not carry ant food items inside the laboratory.

9. Use of cell phones and IPODs is forbidden.

10. Students should not write on or deface any lab desks, computers, or any equipment provided to them during the experiment.

11. Every student should keep his/her work area properly before leaving the laboratory.

PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROGRAM -1 Date:

Aim:

A) Write python program to print Hello World Program:

print("Hello World") Output:

Hello World Exercise Questions:

A) Write a python program to get string, int, float input from user B) Write a python program to add 2 numbers Viva Questions:

1. Define python?

2. Write the steps to install and set path to python?

3. List out differences between interactive mode and script mode?

Signature of the Faculty PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in Record Notes PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER

MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROGRAM -2 Date:

Aim:

A) Create a list and perform the following methods 1) insert() 2) remove() 3) append() 4) pop() 5) clear() Program:

a=[1,3,5.7,"hello","food"] print(a) a.insert(4,"mrcet") print(a) a.remove("food")

print(a) a.append("cse") print(a) print(a.pop()) print(a.clear())

Output:

[1, 3, 5.7, 'hello', 'food'] [1, 3, 5.7, 'hello', 'mrcet', 'food'] [1, 3, 5.7, 'hello', 'mrcet'] [1, 3, 5.7, 'hello', 'mrcet', 'cse'] cse

None Exercise Questions:

B) Write a python program to find the length of list?

C) Write a python program to find the smallest and largest number in the list?

Viva Questions:

1. Define and create a list?

2. Justify the list is mutable with example?

3. List out different methods of list with one example each?

Signature of the Faculty PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in Record Notes PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in

PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROGRAM -3 Date:

Aim:

A) Create a tuple and perform the following methods 1) Access items 2) len() 3) check for item in tuple 4)Add item Program:

tup=(1,2,3,4,5,'a','bb','c','xyz') print("Items in a tuple") for i in tup:

print(i,end=" ") print(" \nLength of tuple",len(tup)) i=int(input("enter a value")) print(i in tup) tup[1]="hello"

print(tup) Output:

Items in a tuple 1 2 3 4 5 a bb c xyz Length of tuple 9 enter a value4 True

Traceback (most recent call last):

File "C:/Users/hi/tup1.py", line 8, in tup[1]="hello" TypeError: 'tuple' object does not support item assignment Exercise Questions:

B) Write a python program using the following methods: 1) count 2) index C) Write a python program using “+” and “*” operations which resulting a new tuple?

Viva Questions:

1. Define tuple?

2. Define indexing and slicing?

3. Demonstrate python casting with one example?

4. Difference between tuple and list?

Signature of the Faculty PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in Record Notes PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER

MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in

PROGRAM -4 Date:

Aim:

A) Create a dictionary and apply the following methods 1)Print the dictionary items 2) access items 3) use get() 4)change values 5) use len() Program:

dict={'Name': 'mrcet', 'Age': 20} print(dict.items()) print(dict) print(dict.get("Age")) dict[3]="college"

print(dict) print(len(dict)) Output:

dict_items([('Name', 'mrcet'), ('Age', 20)]) {'Name': 'mrcet', 'Age': 20} 20 {'Name': 'mrcet', 'Age': 20, 3: 'college'} 3

Exercise Questions:

B) Write a python code to convert list of tuples into dictionaries?

C) Write python program to store data in list, tuple, set, dictionary and then try to print them.

Viva Questions:

1. Define dictionary?

2. Differentiate between list, tuple, set, dictionary 3. Write the syntax to access keys, values and item of a dictionary?

Signature of the Faculty PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in Record Notes PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in

PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER

MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROGRAM -5 Date:

Aim:

A) Write a python program to perform arithmetic, assignment, logical and comparison operators?

Program:

a=int(input(“enter a value”)) b= int(input(“enter b value”)) print(a+b) print(a is not b) print(a and b)

print(a==b) Output:

enter a value10 enter b value20 30 True 20

False Exercise Questions:

A) Write a Python program to add two positive integers without using the '+' operator. (use bitwise operator) B) Write a Python program to perform the basic four operators (+, -, *, /) Viva Questions:

1. Define precedence of operators with an example?

2. List out different types python basic operators with on example each?

3. Explain bitwise, membership and identity operators?

Signature of the Faculty PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in Record Notes PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER

MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in

PROGRAM -6 Date:

Aim:

A) Write a simple python program to declare a variable in different possible ways?

Program:

a=10 print(a) a=b=c=1 print(a) print(b)

print(c) a,b,c=1,"hello",5.6 print(a,b,c) a=20 print(a)

Output:

10 1 1 1 1 hello 5.6

20 Exercise Questions:

A) Write a python program to show precedence of operators using the expression: z = (v+w) * x / y B) Write a python program to check whether the values of a list exist or not (use membership operator) and also perform identity operation?

Viva Questions:

1. List out the rules of variables?

2. Explain output variables?

3. Define python expression with an example?

Signature of the Faculty PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in Record Notes PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER

MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROGRAM -7 Date:

Aim:

A) Write a python program to print a number is positive/negative using if-else.

Program:

a=int(input("enter a number")) if a>0:

print(a,"is positive") else:

print(a,"is negative") Output:

enter a number -1 -1 is negative Exercise Questions:

B) Write a python program to find largest number among three numbers.

C) Write a python Program to read a number and display corresponding day using if_elif_else?

D) Write a python program to print list of numbers using range and for loop Viva Questions:

1. List out various control flows?

2. Write the syntax of for and while loops?

3. Difference between for and while loops?

Signature of the Faculty PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in Record Notes PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER

MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in

PROGRAM -8 Date:

Aim:

A) Write a python code to print the sum of natural numbers using while loop?

Program:

num = int(input("Enter a number: ")) if num < 0:

print("Enter a positive number") else:

sum = 0 # use while loop to iterate un till zero while(num > 0):

sum += num num -= 1 print("The sum is",sum) Output:

Enter a number: 6 The sum is 21 Exercise Questions:

A) Write a python program to print the factorial of given number?

B) Write a python program to find the sum of all numbers stored in a list using for loop?

Viva Questions:

1. Define loop?

2. Write a python program to iterate over a list and string?

3. Demonstrate a python code for nested while loop?

Signature of the Faculty PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in Record Notes PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER

MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROGRAM -9 Date:

A) Using a numpy module create an array and check the following:

1. Type of array 2. Axes of array 3. Shape of array 4. Type of elements in array Program:

import numpy as np arr=np.array([[1,2,3],[4,2,5]]) print("Array is of type:",type(arr)) print("no.of dimensions:",arr.ndim) print("Shape of array:",arr.shape)

print("Size of array:",arr .size) print("Array stores elements of type:",arr.dtype) Output:

Signature of the Faculty PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in Exercise Questions:

B) Using a numpy module create array and check the following:

1. List with type float 2. 3*4 array with all zeros 3 . From tuple 4. Random values Viva Questions:

1. Define array?

2. What is the purpose of numpy in python?

3. Difference between List and Array?

PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in Record Notes PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in

PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROGRAM -10 Date:

Aim:

A) Write python program in which an function is defined and calling that function prints Hello World Program:

def hello():

print(“Hello World”) hello() Output:

Hello World Exercise Questions:

B) Write python program in which an function (with single string parameter ) is defined and calling that function prints the string parameters given to function.

C) Write a python program using with any one of python function argument?

Viva Questions:

1. Define built -in and user defined function?

2. What are the different types of python function arguments?

3. Differentiate between parameter and arguments in functions?

Signature of the Faculty PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in Record Notes PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER

MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in

PROGRAM -11 Date:

Program:

double = lambda x:2*x print(double(5)) add = lambda x,y:x+y print(add(5,4)) Output:

10 9 Exercise Questions:

B) Write a program for filter() to filter only even numbers from a given list.

C) Write a program for map() function to double all the items in the list?

D) Write a program to find sum of the numbers for the elements of the list by using reduce()?

Viva Questions:

1. Define lambda function with syntax?

2. List out difference between built -in functions and anonymous functions?

3. Write the syntax for filter, map, and reduce functions?

4. Define fruitful functions?

Signature of the Faculty PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in Record Notes PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in

PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROGRAM -12 Date:

Aim:

A) Write a python program to open and write “hello world” into a file?

Program:

f=open("1.txt","a") f.write("hello world") f.close() Output:

If we keep on executing the same program for more than one time then it append the data that many times Signature of the Faculty PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in Exercise Questions:

A) Write a python program to write the content “hi python programming” for the existing file.

B) Write a python program to concatenate two files into third file?

Viva Questions:

A) Define file and list the different modes of a file?

B) Differentiate between text file and binary file?

C) Write the syntax to open a file?

PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in Record Notes PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER

MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROGRAM -13 Date:

Aim:

A) Write a python program to append data to an existing file and then displaying the entire file.

Program:

fp=open("abc.txt","w") fp.write("Hello world") fp.close() fp=open("abc.txt","a") fp.write(" \nwelcome to python program")

fp.close() fp=open("abc.txt","r") print(fp.read()) fp.close() OUTPUT:

Hello world welcome to python program Exercise Questions:

2) Write a python program to open a new file, add some data into it and display the contents of that file.?

Viva Questions:

1) What are the file I/O operations in python?

2) What is the purpose of file modes in python?

Signature of the Faculty PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in Record Notes PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER

MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in PROGRAM -14 Date:

Aim:

A) Write a python program to handle the ZeroDivisonError exception.

PROGRAM:

try:

a = int(input('Enter a number: ')) b = int(input('Enter a number: ')) c = a / b print('Result: ', c) except ZeroDivisionError :

print('Exception_1: value of b can not be zero!') else:

print('No exception occurred!!!') finally:

print('This is executed compulsory!!!') Exercise Questions:

1)Write a python program to demonstrate multiple except block with a single try block Viva Questions:

1) What is an exception?

2) What is Runtime error?

3) Write the syntax of multiple exceptions in python?

Signature of The Faculty PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER MRCET EAMCET CODE : MLRD www .mrcet.a c.in Record Notes PROBLEM SOLVING USING PY THON PROGRAMMING LAB B TECH I YEAR I S EMESTER

MRCET EAMCET CODE : MLRD www .mrcet.a c.in