Modules 3,4 & 5

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

1.

Write a Pandas program to select the rows where the number of attempts in the
examination is greater than 2.
Sample Python dictionary data and list labels:
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael',
'Matthew', 'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, 17.6, 9, 20, 14.5, 18.6, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']}
2. Write a Pandas program to replace all the NaN values with mean in a column of a
dataframe.
3. Write a python program to create data frame using with the name Employee with titles as
Empid, Empname, Empdesig. Insert 10 records into it and display them. Add the title
Empcontact as a new title and display the results.
4. With a given tuple (1,2,3,4,5,6,7,8,9,10), write a program to print the first half values in
one line and the last half values in one line.
5. Write a program to read the information present in a welcome1.txt file such as student
name, roll no and also append the information such as contact address, parent details, and
city zip code and display it.
6. Write a program to count the vowels, consents, digits, and special symbols present in a
file.
7. Write a program to copy the information from one file to another.
8. Write a python program to check whether a given no is prime no or not using functions.
9. Program to get the difference between the two tuples.

10. Given list of tuples, remove all the tuples with length K. Input : test_list = [(4, 5), (4, ),
(8, 6, 7), (1, ), (3, 4, 6, 7)], K = 2 Output : [(4, ), (8, 6, 7), (1, ), (3, 4, 6, 7)] Explanation :
(4, 5) of len = 2 is removed.
11. Program to generate and print a dictionary that contains a number (between 1 and n) in
the form (x, x*x). Sample Input: (n=5) : Expected Output : {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
12. Given an integer tuple, for each element in the tuple check whether there exists a
smaller element on the next immediate position of the array. If it exists print the smaller
element. If there is no smaller element on the immediate next to the element then print -1.
Example Input: 4 2 1 5 3 Output: 2 1 -1 3 -1

13. Python Program to Generate Random Numbers from 1 to 20 and Append Them to the
List.
14. Write a program to explore all 11 attributes of the series in pandas.
15. Write a pandas program to display employee details whose salary is >25000 and <50000,
from employee dataset and also display employee names contains character ‘s’ using
compound condition.
16. Write a Python program that matches a string that has an 'a' followed by anything ending in 'b'.
Sample Input:
S1= "aabbbbd"
S2= "aabAbbbc"
S3= "accddbbjjjb"

Sample Output:
Not matched!
Not matched!
Found a match!

17. Write a Python program to match if two words from a list of words start with the letter 'P'.

Sample Input:
words = ["Python PHP", "Java JavaScript", "c c++"]

Sample Output:
('Python', 'PHP')

18. Write a Python program to replace a maximum 2 occurrences of space, comma, or dot with a
colon.

Sample Input:
text = 'Python Exercises, PHP exercises.'

Sample Output:
Python: Exercises: PHP exercises.

19. Write a Python program to retrieve the phone number and house number from the given string.

Sample Input:
s='Rahul Mbl No:9848498544 and his H.No:18574'

Sample Output:
['9848498544', '18574']

20. program to create a reg. exp to split a string into pieces where one or more non-alphanumeric
chars are found

Sample Input:
s='This; is the: core \ python book'

Sample Output:
['This', 'is', 'the', 'core', 'python', 'book']
21. John is struggling to pass a certain college course. The test has a total of N
questions, each question carries 3 marks for a correct answer and −1 for an incorrect
answer. John is a risk-averse person so he decided to attempt all the questions. It
is known that John got X questions correct and the rest of them incorrect. For John
to pass the course he must score at least P marks. Will John be able to pass the
exam or not?
Sample Input:

5 (no. of Questions)

2 (no. of Correct Questions)

10 (Passing Marks)

Sample Output:

John has Failed in the exam

Description:

John got 5 Questions to answer, out of 5 Questions 2 Questions are correct,


and the Minimum passing mark is 10.

22. Team RCB has earned X points in the games it has played in this 2023 IPL. To
qualify for the playoffs, they must make at least a total of Y points. They have
currently Z games left, in each game, they get 2 points if they win. On losing one
game RCB team point is deducted by 1. Out of Z games left RCB wins W games
and loses L games. RCB fans are waiting to know whether is it possible for RCB to
qualify for the playoffs this year or not.

Sample Input:

Earned Points 6

Required points to Qualify for Playoff 10

Games left 8

Games Won 4

Games Lost 4

Sample Output:

Hurray RCB Qualified for the playoff

You might also like