0% found this document useful (0 votes)
0 views4 pages

Lab 1

The document outlines a comprehensive series of Python labs designed to teach fundamental programming concepts, including basic syntax, conditional statements, loops, data structures, functions, file handling, exception handling, and object-oriented programming. Each lab contains specific objectives and practical exercises to reinforce learning, such as performing arithmetic operations, manipulating strings, and implementing classes. The structure aims to provide a hands-on approach to mastering Python programming skills.

Uploaded by

ganpatikrathia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views4 pages

Lab 1

The document outlines a comprehensive series of Python labs designed to teach fundamental programming concepts, including basic syntax, conditional statements, loops, data structures, functions, file handling, exception handling, and object-oriented programming. Each lab contains specific objectives and practical exercises to reinforce learning, such as performing arithmetic operations, manipulating strings, and implementing classes. The structure aims to provide a hands-on approach to mastering Python programming skills.

Uploaded by

ganpatikrathia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab 1: Introduction to Python & Basic I/O

Objective: Understand Python syntax, variables, and input/output.

1. Print "Hello, World!" in Python.


2. Take a user's name as input and display a greeting.
3. Take two numbers as input and print their sum.
4. Display data types of different values (int, float, str, bool).
5. Swap two numbers using a third variable.
6. Swap two numbers without using a third variable.
7. Find the square and cube of a given number.
8. Convert temperature from Celsius to Fahrenheit.
9. Take user input for age and display whether they are eligible to vote (>=18).
10. Perform basic arithmetic operations (+, -, *, /, %, **, //).

Lab 2: Conditional Statements


Objective: Learn if-else and elif statements.

1. Check if a number is even or odd.


2. Find the largest of three numbers.
3. Check whether a given year is a leap year.
4. Create a simple calculator using if-else (Add, Subtract, Multiply, Divide).
5. Check if a number is positive, negative, or zero.
6. Determine the grade of a student based on marks (A, B, C, Fail).
7. Check whether a character is a vowel or consonant.
8. Find whether a number is divisible by 5 and 11.
9. Check whether a triangle is valid based on three sides.
10. Check whether a given character is uppercase, lowercase, digit, or special symbol.

Lab 3: Loops (for & while)


Objective: Learn looping constructs (for, while).

1. Print numbers from 1 to N using a for loop.


2. Print numbers from N to 1 using a while loop.
3. Display the multiplication table of a given number.
4. Find the factorial of a number.
5. Generate a Fibonacci series up to N terms.
6. Print all even numbers between 1 and 50.
7. Count the number of digits in a given number.
8. Reverse a given number.
9. Check if a number is prime.
10. Find the sum of digits of a number.

Lab 4: Lists and Tuples


Objective: Learn about list and tuple operations.
1. Create a list and perform insert, delete, and update operations.
2. Find the largest and smallest element in a list.
3. Sort a list of numbers in ascending order.
4. Count the occurrences of an element in a list.
5. Find the sum and average of elements in a list.
6. Convert a tuple into a list and vice versa.
7. Extract even and odd numbers from a list.
8. Reverse a list without using the reverse() function.
9. Find the second largest number in a list.
10. Merge two lists into a single sorted list.

Lab 5: Dictionaries and Sets


Objective: Understand dictionaries and sets in Python.

1. Create a dictionary with student names and marks.


2. Fetch a value from the dictionary using a key.
3. Add and remove elements from a dictionary.
4. Count the frequency of words in a string using a dictionary.
5. Perform union, intersection, and difference operations on sets.
6. Convert a list into a set to remove duplicates.
7. Find common elements between two lists using sets.
8. Sort a dictionary based on keys.
9. Create a dictionary from user input (keys and values).
10. Check if a key exists in a dictionary.

Lab 5: String Manipulation


1. Write a Python program that takes a string input from the user and capitalizes the first
letter of the string.

2. Count the Number of Vowels in a String

3. Check if a String is a Palindrome

Q4: Convert String to Uppercase and Lowercase

Q5: Find the Frequency of a Character in a String

Q6: Replace a Substring in a String

Q7: Split a String into Words

Q8: Join a List of Words into a String

Q9: Find the Longest Word in a Sentence

Q10: Remove Punctuation from a String


Additional Activities:
 Experiment with string slicing to extract specific parts of a string.
 Use strip(), lstrip(), and rstrip() to remove whitespace.
 Explore formatting options with format() and f-strings.

Lab 7: Functions & Recursion


Objective: Learn function definition, parameters, and recursion.

1. Create a function to find the factorial of a number.


2. Create a function to check if a string is a palindrome.
3. Write a function to calculate the area of a circle.
4. Create a function to swap two numbers.
5. Write a function to find the largest of three numbers.
6. Implement a recursive function for the Fibonacci series.
7. Implement a function to count vowels in a string.
8. Find the sum of elements in a list using a function.
9. Write a function to check if a number is perfect (sum of divisors = number).
10. Create a function to return the GCD of two numbers.

Lab 8: File Handling


Objective: Learn how to read, write, and manipulate files.

1. Open a file and read its contents.


2. Write data to a file.
3. Append new data to an existing file.
4. Copy contents from one file to another.
5. Count the number of words in a file.
6. Count the number of lines in a file.
7. Find the longest word in a file.
8. Find the number of occurrences of a word in a file.
9. Read a file and print only even-numbered lines.
10. Merge the contents of two files into a new file.

Lab 9: Exception Handling


Objective: Learn error handling with try-except.

1. Handle division by zero error.


2. Handle invalid input type errors.
3. Implement try-except for file handling errors.
4. Catch multiple exceptions in a single try-except block.
5. Handle list index out-of-range errors.
6. Implement finally block in exception handling.
7. Raise a user-defined exception for invalid input.
8. Handle KeyError in dictionary operations.
9. Implement exception handling for division operation with user input.
10. Use assert statements for input validation.

Lab 10: Object-Oriented Programming (OOP)


Objective: Learn Python classes and objects.

1. Create a class for a student with attributes like name, roll number, and marks.
2. Implement a class method to display student details.
3. Create a BankAccount class with deposit and withdrawal methods.
4. Implement a class with both instance and static methods.
5. Create a Rectangle class with area and perimeter methods.
6. Implement inheritance with a base class and derived class.
7. Create a class for a library management system.
8. Implement method overriding in Python.
9. Create a class for an employee and compute salary details.
10. Implement operator overloading using a class.

You might also like