Welcome to the MCALab3 repository! This repository contains solutions to various programming problems organized by week. Each week focuses on different concepts and challenges to enhance your programming skills.
The repository is organized into fourteen folders, each corresponding to a week of lab exercises:
- Week1
- Week2
- Week3
- Week4
- Week5
- Week6
- Week7
- Week8
- Week9
- Week10
- Week11
- Week12
- Week13
- Week14
- PracticeQuestions
Each folder contains multiple problems with specific objectives. Below is a detailed list of the problems tackled in each week.
- Problem1: Write a program to find the product of two user-supplied integers and if the product is equal to or lower than 5000, return the sum of the two numbers.
- Problem2: Write a program to print the sum of the first 10 numbers.
- Problem3: Write a program to iterate through a supplied list of 20 numbers and print only those numbers which are divisible by 5.
- Problem4: Write a program to check if the given number is a palindrome.
- Problem5: Write a program to calculate the cube of all numbers from 1 to a given number.
- Problem1: Write a program to extract each digit from an integer in reverse order.
- Problem2: Write a program to count the total number of digits in a number using a while loop.
- Problem3: Write a program to display all prime numbers within a range.
- Problem4: Write a program to use a loop to find the factorial of a given number.
- Problem5: Write a program to find the sum of digits of a supplied integer.
- Problem1: Write a program to print the following pattern using a for loop:
5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 - Problem2: Write a program to print the following star pattern using a for loop:
* * * * * * * * * * * * * * * * * * * * * * * * * - Problem3: Write a program to print characters from a string which are present at even index numbers.
- Problem4: Write a program to accept a string from the user and display characters that are present at even index numbers.
- Problem5: Write a program to remove characters from a string starting from position
nto the end and return a new string. Example:remove_chars("aligarh", 3)should returnali.
- Problem1: Write a program to create a function
cal_sum_sub()that can accept two variables and calculate both their addition and subtraction. It should return both addition and subtraction in a single return call. - Problem2: Write a function to return
Trueif the first and last number of a given list are the same. Otherwise, returnFalse. - Problem3: Given a list of numbers, write a program to turn every item of the list into its square.
- Problem4: Given two Python lists, write a program to iterate through both lists simultaneously and display items from the first list in the original order and items from the second list in reverse order.
- Problem5: Write a program to count the number of occurrences of the item
50in the tupletp1 = (50, 10, 60, 70, 50).
- Problem1: Write a program to generate a 6-digit random secure OTP.
- Problem2: Write a program to pick a random character from a given string supplied by the user.
- Problem3: Write a program to generate a random password that meets the following conditions:
- Password length must be 10 characters long.
- It must contain at least 2 uppercase letters, 1 digit, and 1 special symbol.
- Problem4: Given two lists of numbers, write a program to create a new list that contains odd numbers from the first list and even numbers from the second list.
- Problem5: Write a program to create a NumPy array and return an array of odd rows and even columns from the NumPy array.
- Problem6: Write a program to create a NumPy array and sort it based on the following cases:
- Case 1: Sort the array by the second row.
- Case 2: Sort the array by the second column.
- Problem1: Write a Python program that inputs two tuples and creates a third that contains all elements of the first followed by all elements of the second. (You may use other data types such as lists to make your program work.)
- Problem2: Write a Python program to create a dictionary with names and phone numbers. The names should act as keys and the phone numbers as values. Then, ask the user for a name and print the corresponding phone number.
- Problem3: Write a Python program with a void function that receives a 4-digit number and calculates the sum of squares of the first 2 digits and the last 2 digits. For example, if
1233is passed as an argument, the function should calculate12^2 + 33^2. - Problem4: Write a program that inputs a main string and creates an encrypted string by embedding a short symbol-based string after each character. The program should also be able to decrypt the encrypted string.
- Problem5: Write a program to get roll numbers, names, and marks of students of a class (input from the user) and store these details in a file called "Marks.data".
- Problem6: Write a program to accept a string and display the following:
- Number of uppercase characters
- Number of lowercase characters
- Total number of alphabets
- Number of digits
-
Problem 1: Write a report on different types of Linux shells (sh, csh, ksh, bash).
-
Problem 2: Copy, move, and remove files using
cp,mv, andrmcommands. -
Problem 3: Create and delete directories using
mkdirandrmdir. -
Problem 4: Change the current working directory using
cdand display the present working directory usingpwd. -
Problem 5: Consider two files that contain information about Employees and Departments in the following parameters:
- Employee: (Name, EId, Salary, DID)
- Department: (DID, DName, DLocation)
Write a Python program to find the average salary of each department.
-
Problem 6: Consider two files having some lines of statements. Write a Python program to swap the content present at the middle line of the first file with the content of the last line of the second file. (Note: The first file contains an odd number of lines of statements.)
-
Problem 1: Display detailed information about files using
ls -land otherlsoptions. -
Problem 2: Change file ownership using
chownand group ownership usingchgrp. -
Problem 3: Modify file and directory permissions using
chmod. -
Problem 4: Demonstrate how to set and remove directory permissions.
-
Problem 5: Write a Python program that reads a string which contains English alphabets and numbers. The program should create two lists,
L1andL2, whereL1includes all the numbers present in the string whileL2includes all the alphabets of the string. -
Problem 6: Write a program in Python to find vowels having the maximum number of instances in a given file.
- Note: The file contains a variety of data such as English alphabets, numbers, etc.
-
Problem 7: Write a Python program to create a list of user-supplied distinct integers having an even number of elements. The program further creates two lists of equal lengths based on the original list, where the first list contains all elements less than the elements of the second list. Display both lists.
-
Problem 1: Write a report on the structure of the Linux file system.
-
Problem 2: Display inode information using
ls -iand interpret the results. -
Problem 3: Create and delete files and directories, and observe changes in inode numbers.
-
Problem 4: Explain the significance of inodes in file management and demonstrate with examples.
-
Problem 5: Write a Python program to find the alphabet/s having the maximum number of instances in a given file.
-
Problem 6: A file contains information about programs and courses in the following format:
Program Course MCA Database MCA Java M.Sc Data Structure B.Sc Python Write a Python program to find the number of courses against each program.
- Expected Output:
MCA-2, M.Sc-1, B.Sc-1
- Expected Output:
-
Problem 7: A file contains information about employees with the following parameters:
Name id salary Dname Amar 101 20000 Sales Ammar 102 22000 Marketing Rahil 103 18000 Sales Write a Python program to add one more column,
HRA(House Rent Allowances), to this file, whereHRA = 18% of salary.
-
Problem 1: Write a simple shell script to display "Hello, World!" on the terminal.
-
Problem 2: Write a shell script to accept user input and display it.
-
Problem 3: Write a shell script to demonstrate the use of variables.
-
Problem 4: Write a shell script to perform basic arithmetic operations.
-
Problem 5: Write a Python program to find the word/s having the maximum number of instances in a given file and replace all its occurrences with “Aligarh”.
-
Problem 6: Consider two files that contain information about Employees and Departments with the following parameters:
Employee File:
Name EId Salary DID Department File:
DID DName DLocation Write a Python program to merge the content of both files into the following format:
Emp_Dep:
Ename Eid Esalary EDID DName DLocation Note: Merging should follow the condition that the DID of the Employee file should be equal to the DID of the Department file.
-
Problem 1: Write a shell script to check if a file exists and display an appropriate message.
-
Problem 2: Write a shell script to find the factorial of a number using loops.
-
Problem 3: Write a shell script to demonstrate the use of conditionals (if-else statements).
-
Problem 4: Write a shell script to create and use a simple function.
-
Problem 5: You have been given a dataset
demo.csvwith the following features:- Independent Features: x1, x2, x3, x4, x5, x6, x7
- Dependent Feature: y (with values either 0 or 1)
All independent features are continuous data except x1 and x2, which are nominal data.
Write a Python program to:
a. Clean independent features.
b. Add one more feature x7 having values between 0 and 1.
c. Perform scaling.
d. Train this dataset using Logistic Regression, Decision Tree, and Random Forest. Compare the performance of all the models based on accuracy and F1 score.
e. Draw a confusion matrix for each model.
-
Problem 1: Write a shell script to back up a directory to a specified location.
-
Problem 2: Write a shell script to monitor disk usage and send an alert if usage exceeds a threshold.
-
Problem 3: Write a shell script to automate the creation of user accounts.
-
Problem 4: Write a shell script to search for a specific pattern in a file and display the results.
-
Problem 5: Consider two features x1 and x2 based on the following function:
y=x1^2 + 3x2 + c
where
cis generated based on 1000 random values between 0 and 1.- Generate 1000 random values between 0 and 1 for x1 and x2.
- Calculate y based on the above function.
- Train a Polynomial Regression model and check the score for the same.
-
Problem 1: Write a report on the architecture and features of Linux.
-
Problem 2: Create and edit a text file using the
vieditor. -
Problem 3: Execute basic Linux commands such as
pwd,cd,ls,mkdir, andrmdir. -
Problem 4: Create a text file in the
vieditor, make changes, and save it. -
Problem 5: Consider the MNIST dataset, which contains 70,000 small square 28×28-pixel grayscale images of handwritten single digits between 0 and 9. Train a model to classify images as digit 8 (Binary classification problem). Discuss the performance of the model.
-
Problem 1: Develop a shell script to automate the setup of a web server, including installing necessary packages and configuring the server.
-
Problem 2: Write a shell script to perform a system health check, including checking CPU usage, memory usage, and disk space, and generate a report.
-
Problem 3: Create a shell script to manage user permissions and automate the backup of critical files.
-
Problem 4: Write a comprehensive shell script to manage and rotate system logs, ensuring old logs are archived and deleted after a certain period.
-
Problem 5: You have been given a dataset
temp.csvwith the following features:- Independent Features: x1, x2, x3, x4, x5
- Dependent Feature: y (with values either 0 or 1)
All independent features are continuous data except x5, which is nominal data.
Write a Python program to:
a. Clean independent features (if any).
b. Draw a heatmap to show correlations among independent features.
c. Train this dataset using Logistic Regression, Decision Tree, and Random Forest. Compare the performance of all models based on accuracy and F1 score.
d. Draw a confusion matrix for each model.
e. Check whether scaling improves performance or not.
-
Problem 6: Consider two features x and y based on the following function:
y=3x+kwhere
kis generated based on 1000 random values between 0 and 1.- Generate 1000 random values between 0 and 1 for x.
- Calculate y based on the above function for these 1000 values of x.
- Train a Linear Regression model and check the score for the same.
-
Problem 1: Write a program to read five real numbers from the user and find the average and standard deviation.
-
Problem 2: Write a program to compute the value of the following algebraic expression:
(1 + (x / y) + x^y) / (2 + (y / x) + y^x)
The values of x and y will be input using the
input()function. -
Problem 3: Write a program to read an integer and use bitwise operators to multiply it by 2 (<< operator).
-
Problem 4: Write a program to read an integer and use bitwise operators to divide it by 4 (>> operator).
-
Problem 5: Write a program to read the values of two integer variables and use bitwise operators to exchange the values of the variables (^ operator).
-
Problem 6: Write a program to read the values of two integer variables and exchange the values (Use addition and subtraction operators).
-
Problem 7: What should be the value of
3 << 3 ^ 2 & 1 + 3? -
Problem 8: Write a program to read an integer and use bitwise operators to check the nature (even or odd) of the integer.
- Property:
- The binary representation of every odd integer consists of 1 at the rightmost position.
- The binary representation of every even integer consists of 0 at the rightmost position.
- Property:
-
Problem 9: Write a program to find the maximum of three numbers.
-
Problem 10: Write a program to read the values of two points on the x-y plane and find out the distance between the two points. Use math functions (
sqrt,pow). -
Problem 11: Write a program to compute the factorial of an integer.
-
Problem 12: Write a program to check whether an integer is prime.
-
Problem 13: Write a program to find prime numbers between two numbers.
-
Problem 14: Write a Python function to calculate the sum of digits of a given integer.
-
Problem 15: Write a function to add arbitrary integers.
-
Problem 16: Write a function to receive multiple strings and count the total number of characters.
-
Problem 17: Write a Python program to check whether a string is a palindrome or not.
-
Problem 18: Write a Python program that first accepts a string and, if the string length is less than 4, returns an empty string. Then create a string made of the first 2 and the last 2 characters from the accepted string.
- Sample String: ‘New Delhi’
- Expected Result: ‘Nehi’
- Sample String: ‘New’
- Expected Result: Empty String
- Sample String: ‘ w’
- Expected Result: Empty String
- Problem 19: Write a Python program to delete ‘e’ from the end of a given string (length should be at least 3) and add ‘en' at the end. If the string length of the given string is less than 3, leave it unchanged.
- Sample String: ‘Give’
- Expected Result: ‘Given’
- Sample String: ‘take’
- Expected Result: ‘taken’
- Sample String: ‘ta’
- Expected Result: ‘ta’
-
Problem 20: Given a list containing strings and integers. Write a program to create two separate lists consisting of strings and integers respectively.
-
Problem 21: Write a Python program to sort words in alphabetical order.
-
Problem 22: Write a Python program to read a list and transfer even and odd integers into two different lists.
-
Problem 23: Write a Python program to merge two lists and sort it.
-
Problem 24: Write a Python program to find the second largest number in a list and all its indices.
-
Problem 25: Write a Python program to sort a list according to the length of the elements.
-
Problem 26: Create a list of tuples with the first element as the number and the second element as the square of the number.
-
Problem 27: Write a Python program to remove duplicate items from a list.
-
Problem 28: Write a Python program to find the element occurring an odd number of times in a list.
-
Problem 29: Read a list of words and return the length of the longest one.
-
Problem 30: Write a Python program to find the repeated items of a tuple.
-
Problem 31: Write a Python program to find the index of an item in a tuple.
-
Problem 32: Write a Python program to remove empty tuples from a list of tuples.
-
Problem 33: Write a Python program to count the words in a line of text.
-
Problem 34: Write a Python program to count the number of sentences, words, and the word with the maximum instances in a line of text.
-
Problem 35: Write a Python program to count the frequency of each character in a line of text.
-
Problem 36: Write a Python program to find the character having the maximum count in a line of text.
-
Problem 37: Write a Python program to check whether a sentence is a pangram or not. A pangram is a sentence that contains every letter of the alphabet at least once.
-
Problem 38: Create your own class
Primeto return all primes between two given numbers. -
Problem 39: Write a Python program to read a string and find the number of digits and alphabets.
-
Problem 40: Write a Python program to count the number of lines, words, characters, alphabets, and digits in a file.
-
Problem 41: Write a Python program to find the average value of the second column of a 2D numpy array.
-
Problem 42: Write a Python program to find the average value of the first 5 rows of the third and fourth columns of a 2D numpy array.
-
Problem 43: Write a Python program to compute the row-wise sum of all possible values in a 2D numpy array.
-
Problem 44: Write a Python program to find the maximum value in each row of a 2D numpy array.
-
Problem 45: Write a Python program to find the maximum average value in each row of a 2D numpy array.
- Clone this repository to your local machine using:
git clone https://github.com/azmisaud/MCALab3.git - Navigate to the desired week's folder to explore the problems and their solutions.