Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Department of Computer Science and Engineering
- KPR Institute of Engineering and Technology
- B.E. – COMPUTER SCIENCE AND ENGINEERING
- LABORATORY RECORD
- U21CSG02 – PYTHON PROGRAMMING
- (Regulation 2021)
- KPR INSTITUTE OF ENGINEERING AND TECHNOLOGY
- (Autonomous)
- COIMBATORE – 641 407
- LABORATORY RECORD
- Name
- : ……………………………………………………………….
- Register Number
- : ……………………………………………………………….
- Subject Code & Title: ……………………………………………………………….
- Department
- : ……………………………………………………………….
- Year & Semester
- : ……………………………………………………………….
- This is the certified record of work done by………………………………………….
- Register Number ………………………………………………………
- Staff In- Charge
- Head of the Department
- Place:
- Date:
- He/ She has submitted the record for the End Semester PracticalExamination held
- on ……………………
- Internal Examiner
- Department of Computer Science and Engineering
- KPR Institute of Engineering and Technology
- -----------------------------------------------------------------------------------------------VISION AND MISSION OF THE INSTITUTION
- Vision
- To become a premier institute of academic excellence by imparting technical, intellectual and
- professional skills to students for meeting the diverse need of the industry, society, the nation and the
- world at large.
- Mission
- â– Commitment to offer value-based education and enhancement of practical skills
- â– Continuous assessment of teaching and learning process through scholarly activities
- â– Enriching research and innovation activities in collaboration with industry and institute of repute
- â– Ensuring the academic process to uphold culture, ethics and social responsibility
- VISION AND MISSION OF THE DEPARTMENT
- Vision
- To be a premier centre for education, dissemination of knowledge and research in the frontier areas of
- computer science and engineering to serve the community with moral values.
- Mission
- •
- Provide holistic education incorporating the state-of-the-art technologies to produce successful
- professionals.
- •
- Facilitate the students to pursue higher education and research in the areas related to Computer Science
- and Engineering.
- •
- Promote strong collaborations with the industries and steer the students to nurture their interest in
- continuous learning to meet the changing needs of the society.
- Program Educational Objectives
- Graduates of B.E. CSE program, four years after graduation, will
- PEO 1: Acquire knowledge and skills on cutting edge technologies in the field of computer science and
- engineering.
- PEO 2: Inculcate a passion for continuous learning through further studies and research in the field of
- computer science and engineering.
- PEO 3: Develop innovative ideas upholding the rich value systems to solve the changing technological
- needs.
- Program Outcomes
- PO 1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering
- fundamentals, and an engineering specialization to the solution of complex engineering problems
- PO 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
- PO 3. Design/development of solutions: 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
- PO 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
- PO 5. Modern tool usage: Create, select, 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
- PO 6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess
- societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the
- professional engineering practice
- PO 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
- PO 8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms
- of the engineering practice
- PO 9. Individual and team work: Function effectively as an individual, and as a member or leader in
- diverse teams, and in multidisciplinary settings
- PO 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
- PO 11. Project management and finance: Demonstrate knowledge and understanding of the
- engineering and management principles and apply these to one's own work, as a member and leader in a
- team, to manage projects and in multidisciplinary environments
- PO 12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
- independent and life-long learning in the broadest context of technological change
- Programme Specific Objectives
- PSO 1: Solve complex engineering problems by building integrated systems across various domains of
- Computational Intelligence.
- PSO 2: Apply technical skills to produce solutions that meet the requirements of the emerging
- technologies in Computer Science and Engineering.
- INDEX
- S.NO
- Date
- PAGE
- NO
- NAME OF THE EXPERIMENTS
- 01
- Programs on selection and iteration operations
- 02
- String and its operations
- 03
- Programs using List
- 04
- Programs using Tuples
- 05
- Programs using Sets
- 06
- Programs using Dictionary
- 07
- Exception Handling
- 08
- File Handling
- 09
- Programs using numpy, pandas
- 10
- Programs using dataframes
- Average Marks:
- Marks
- SIGN
- EX.NO : 01
- PROGRAMS ON SELECTION AND ITERATION OPERATIONS
- DATE :
- A. Area and permitter of circle
- AIM :
- To write a python program to calculate the area and perimeter of a circle.
- ALGORITHM :
- Step 1 : Get the length and breadth from the user as l and b
- Step 2 : Compute the area using the formula l*b
- Step 3 : Compute the perimeter using the formula 2*(l+b)
- Step 4 : Print the are and the perimeter of the circle
- PROGRAM :
- L = int(input(“Enter Length:â€))
- B = int(input(“Enter Breadth:â€))
- Area = L*B
- Perimeter = 2*(L+B)
- print(“Area of Rectangle is “,Area)
- print(“Perimeter of Rectangle is “,Perimeter)
- OUTPUT:
- Enter Length:10
- Enter Breadth:5
- Area of Rectangle is 50
- Perimeter of Rectangle is 30
- RESULT:
- Thus the python program to compute the area and perimeter of the circle has been executed
- successfully.
- B. Odd or even
- AIM :
- To write a python program to find the given number is odd or even.
- ALGORITHM :
- Step 1 : Get the input from the user
- Step 2 : If the number is divisible by 2, print the number as even number
- Step 3 : Else display the number as odd number
- PROGRAM :
- N = int(input(“Enter number:â€))
- If N%2==0:
- print(N,â€is Evenâ€)
- else:
- print(N,â€is Oddâ€)
- OUTPUT:
- Enter number:10
- 10 is Even
- RESULT:
- Thus the python program to check the given number is odd or even has been executed successfully.
- C. Sum of digits of the given number
- AIM :
- To write a python program to find the sum of the digits of the given number.
- ALGORITHM :
- Step 1 : Get the input n from the user
- Step 2: Initialize the sum value to zero
- Step 3 : Until n>0 repeat the steps 4 to 6
- Step 4 : Compute the value of r using r=n%
- Step 5 : Add the value of r to sum
- Step 6 : Perform n=n//10
- Step 7 : Display the sum
- PROGRAM :
- N = int(input(“Enter number:â€))
- Sum = 0
- While(n>0):
- r = N%10
- sum += r
- N = N//10
- Print(“Sum of digits are “,sum)
- OUTPUT:
- Enter number:123
- Sum of digits are 6
- RESULT:
- Thus the python program to find the sum of digits of the given number has been executed successfully.
- D. Fibonacci Series
- AIM :
- To write a python program to display the numbers in Fibonacci series.
- ALGORITHM :
- Step 1 : Get the input n from the user
- Step 2: Initialize the values of n1 and n2 to -1 and 1
- Step 3 : For n time repeat the steps 4 to 6
- Step 4 : Display the sum of n1 and n2.
- Step 5 : Assign the value of n2 to n1
- Step 6 : Assign the sum to n2
- PROGRAM :
- Terms = int(input(“Enter the number of terms:â€))
- N1 = -1
- N2 = 1
- print(“Fibonacci Series are “)
- for i in range(terms):
- Sum=N1+N2
- print(Sum)
- N1=N2
- N2=Sum
- OUTPUT:
- Enter the number of terms:6
- Fibonacci Series are
- 0
- 1
- 1
- 2
- 3
- 5
- RESULT:
- Thus the python program to display numbers in Fibonacci series has been executed successfully.
- E. Prime or not
- AIM :
- To write a python program to determine whether the given number is prime or not.
- ALGORITHM :
- Step 1 : Get the input n from the user
- Step 2: For I values 2 to n-1 repeat the steps 3 to 4
- Step 3 : if n is divisible by i, display the number as not prime, Goto step 6
- Step 4 : If not divisible by i, increment I by 1.
- Step 5 : If the number is not divisible by any number between 2 to n-1, display it as prime number
- Step 6 : Stop the program
- PROGRAM :
- N = int(input(“Enter number:â€))
- If N==1:
- print(N,â€is not a Prime numberâ€)
- Elif(N>1):
- for i in range(2,N):
- if (N%i) == 0:
- print(N,â€is not a Prime numberâ€)
- break
- else:
- print(N,â€is a Prime numberâ€)
- else:
- print(N,â€is not a Prime numberâ€)
- OUTPUT:
- Enter number:13
- 13 is Prime number
- RESULT:
- Thus the python program to find the given number if prime or not has been executed successfully.
- F. Compute Salary of an employee
- AIM :
- To write a python program to compute salary of an employee.
- ALGORITHM :
- Step 1 : Get the input salary and gender from the user
- Step 2: If the gender is male, the bonus is computed as 5% of salary
- Step 3 : if the gender if female, the bonus is 10% of the salary
- Step 4 : If the salary is less than 10000 additional 2% bonus of salary is given
- Step 5 : Display the salary with bonus.
- Step 6 : Stop the program
- PROGRAM :
- Salary = int(input(“Enter Salaryâ€))
- Gender = input(“Enter Genderâ€)
- Bonus =0
- if (Salary < 10000):
- Bonus = Salary * 0.02
- else:
- Bonus =0
- if (Gender == “Mâ€):
- Bonus += Salary * 0.05
- else:
- Bonus += Salary * 0.1
- print(“Salary isâ€, Salary +Bonus)
- OUTPUT:
- Enter Salary: 8000
- Enter Gender: M
- Salary is 8560
- RESULT:
- Thus the python program to compute salary based on the given condition has been executed
- successfully.
- G. Program to perform specific operation based on user input
- AIM :
- To write a python program get an integer input from a user. If the number is odd, then find the factorial
- of a number and find the number of digits in the factorial of the number. If the number is even, then check
- the given number is palindrome or not.
- ALGORITHM :
- Step 1 : Get a integer as input from the user
- Step 2 : Check the input number is odd or even
- Step 3 : If the number is even then print the number is palindrome or not
- Step 4 : If the number is odd the find the factorial of the number
- Step 5 : Print the number of digits in the factorial of the number
- PROGRAM :
- num=int(input('Enter a number:'))
- if num%2==0:
- rev=0
- temp=num
- while(num>0):
- digit=num%10
- rev=rev*10+digit
- num=num//10
- if(rev==temp):
- print('The given number is a palindrome')
- else:
- print('The given number is not a palindrome')
- else:
- def factorial(num):
- if num==1:
- return num
- else:
- return num*factorial(num-1)
- print('The factorial of',num,'is',factorial(num))
- count=0
- n=factorial(num)
- while(n>0):
- n=n//10
- count=count+1
- print('The number of digits is the factorial of a number is',count)
- OUTPUT :
- Enter a number:5
- The factorial of 5 is 120
- The number of digits is the factorial of a number is 3
- Enter a number:454
- The given number is a palindrome
- Department of CSE
- Preparation (Algorithm)
- (4)
- Observation (Program)
- (4)
- Results (Output)
- (4)
- Interpretation (Validation)
- (4)
- Viva-Voce
- (4)
- Total
- (20)
- RESULT :
- Thus the python program to get an integer input from a user and to find if the number is odd, then find
- the factorial of a number and find the number of digits in the factorial of the number and if the number is
- even, then check the given number is palindrome or not has been executed and the output is verified.
- EX.NO : 02
- String and its operations
- DATE :
- A. Palindrome or not
- AIM :
- To write a python program to find whether the given string is palindrome or not.
- ALGORITHM :
- Step 1 : Get the input string from the user
- Step 2: Determine the reverse of the given string
- Step 3 : if the reverse and original string or equal, display the string is a palindrome
- Step 4 : Else display the string is not a palindrome
- Step 5 : Stop the program
- PROGRAM :
- S = input(“Enter String: â€)
- If s == s[::-1]:
- print("Yes,It is Palindrome")
- else:
- print("No,It is not Palindrome")
- OUTPUT:
- Enter String: malayalam
- Yes,It is Palindrome
- RESULT:
- Thus the python program to check the given string is palindrome or not has been executed
- successfully.
- B. No of vowels
- AIM :
- To write a python program to find the number of vowels in the given string.
- ALGORITHM :
- Step 1 : Get the input string from the user
- Step 2: initialize the count to zero
- Step 3 : Iterate through the elements of the string, If the character is a vowel increment count by 1
- Step 4 : Display the count
- Step 5 : Stop the program
- PROGRAM :
- def vowel_count(str):
- count = 0
- vowel = "aeiouAEIOU"
- for alphabet in str:
- if alphabet in vowel:
- count = count + 1
- print("No. of vowels :", count)
- str = input(“Enter the String:â€)
- vowel_count(str)
- OUTPUT:
- Enter the String: Welcome
- No. of vowels : 3
- RESULT:
- Thus the python program to display the number of vowels in the string has been executed
- successfully.
- C. Display pattern
- AIM :
- To write a python program to display the given string in butterfly pattern.
- ALGORITHM :
- Step 1 : Get the input string from the user
- Step 2: compute the length of string
- Step 3 : iterate I from 0 to len-1
- Step 4 : for every iteration display the ith and len-ith characters, display space for remaining
- characters
- Step 5 : Stop the program
- PROGRAM :
- S = input(“Enter the string :â€)
- L= len(s)
- for i in range(l):
- j=l-1-i
- for k in range(l):
- if (k == i or k == j):
- print(s[k], end="")
- else:
- print(" ", end="")
- print()
- OUTPUT:
- Enter the String: Python
- p
- n
- y
- o
- th
- y
- p
- o
- n
- RESULT:
- Thus the python program to display the number of vowels in the string has been executed
- successfully.
- d. To check whether the second string can be obtained from the first by deletion of none, one or
- more characters
- AIM:
- To write a python program to check whether the second string can be obtained from the first by
- deletion of none, one or more characters.
- ALGORITHM:
- Step 1 : Get two strings as input from the user
- Step 2 : Find the length of the two strings
- Step 3 : Using for loop iterate over the two stings
- Step 4 : Find the second sting can be obtained from the first string
- Step 5 : If the second string and the string obtained are equal
- Step 6 : Compare and print yes when the two strings are equal else print no
- PROGRAM:
- str1=str(input("Enter the first string\n"))
- str2=str(input("Enter the second string\n"))
- str3=''
- temp=0
- len1=len(str1)
- len2=len(str2)
- for iter1 in range(0,len2):
- for iter2 in range(temp,len1):
- if(str2[iter1]==str1[iter2]):
- str3=str3+str1[iter2]
- temp=iter2+1
- break
- if(str2==str3):
- print("yes")
- else:
- print("no")
- OUTPUT:
- Enter the first string
- welcome
- Enter the second string
- come
- yes
- Enter the first string
- welcome
- Enter the second string
- well
- no
- Department of CSE
- Preparation (Algorithm)
- (4)
- Observation (Program)
- (4)
- Results (Output)
- (4)
- Interpretation (Validation)
- (4)
- Viva-Voce
- (4)
- Total
- (20)
- RESULT :
- Thus the python program to check whether the second string can be obtained from the first by
- deletion of none, one or more characters has been executed and the output is verified.
- EX.NO : 03
- Programs using List
- DATE :
- a. Display list elements using positive and negative indexing
- AIM:
- To write a Python Program to use positive and negative indexing in Lists
- ALGORITHM:
- Step 1 : Get the number of elements to be in the list
- Step 2 : Get the elements for the list
- Step 3 : Get the elements to be searched in the list
- Step 4 : Print the positive index from the list
- Step 5 : Calculate the negative index by (length of list – index of the searched element)
- Step 6 : Print the negative index from the list
- PROGRAM:
- n=int(input("Enter number of elements in list "))
- l=list()
- for i in range(0,n):
- e=input("enter the value")
- l.append(e)
- print ("Original list : " + str(l))
- k=input("Enter the element to be searched in the lsit ")
- res=len(l)-l.index(k)
- print("The required Negative index : -",str(res))
- print("The required Positive index : ",l.index(k))
- '''res = ~l[::-1].index(k)
- print("The required Negative index : ",str(res))'''
- OUTPUT:
- Enter number of elements in list 10
- enter the value100
- enter the value67
- enter the value56
- enter the value4
- enter the value26
- enter the value45
- enter the value89
- enter the value78
- enter the value80
- Original list : ['100', '67', '56', '4', '26', '45', '89', '78', '80', '34']
- Enter the element to be searched in the lsit 100
- The required Negative index : - 10
- The required Positive index : 0
- RESULT :
- Thus the Python program to perform list and its operations on indexing has been executed and the
- output is verified.
- b. Sum of elements in the list
- AIM:
- To write a Python Program to perform sum of elements in the List
- ALGORITHM:
- Step 1 : Get the number of elements to be in the list
- Step 2 : Get the elements for the list
- Step 3 : Initialize sum to zero
- Step 4 : For each element in the list, add the value to sum
- Step 4 : Display the sum
- PROGRAM:
- L=[]
- sum =0
- N = int(input(‘Enter number of elements: â€))
- for i in range(n):
- L.append(int(input()))
- for i in L:
- sum =sum + i
- print(“List is â€,L)
- print(“sum of elements are “,sum)
- OUTPUT:
- Enter number of elements: 4
- 10
- 20
- 30
- 40
- List is [10,20,30,40]
- Sum of elements are 100
- RESULT :
- Thus the Python program to compute the sum of elements of the list has been executed and the
- output is verified.
- c. Sum of odd and even numbers in the list
- AIM:
- To write a Python Program to perform sum of odd and even elements in the List
- ALGORITHM:
- Step 1 : Get the number of elements to be in the list
- Step 2 : Get the elements for the list
- Step 3 : Initialize oddsum and evensum to zero
- Step 4 : For each element in the list, repeat steps 5 and 6
- Step 5 : If the number is odd, add it to oddsum
- Step 6 : else add the number to evensum
- Step 7 : Display the oddsum and evensum
- PROGRAM:
- L = []
- Evensum ,Oddsum = 0,0
- N = int(input(“Enter number of elements: â€))
- for i in range(n):
- L.append(int(input()))
- for i in L:
- If i%2 ==0:
- Evensum +=i
- else:
- Oddsum+=i
- print(“List is â€,L)
- print(“Sum of even numbers are â€,Evensum)
- print(“Sum of odd are â€,Oddsum)
- OUTPUT:
- Enter number of elements: 4
- 11
- 22
- 33
- 44
- List is [11,22,33,44]
- Sum of even numbers are 66
- Sum of odd numbers are 44
- RESULT :
- Thus the Python program to compute the sum of odd and even elements of the list has been
- executed and the output is verified.
- d. Sorting a list and finding second maximum element in the list
- AIM:
- To write a Python Program to find the second maximum element in the List
- ALGORITHM:
- Step 1 : Get the number of elements to be in the list
- Step 2 : Get the elements for the list
- Step 3 : Sort the elements of the list in ascending order
- Step 4 : Display the second last element as second maximum element
- PROGRAM:
- L = []
- N = int(input(‘Enter number of elements: â€))
- for i in range(n):
- L.append(int(input()))
- print(“List is “,L)
- for i in range (len(L):
- for j in range (i+1,len(L):
- If L[i]>L[j]:
- L[i
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement