Exam on Python Programming
Exam on Python Programming [Time: 1 hr]
[Total Marks: 100]
Marks
Q1. Count all letters, digits, and special symbols from a given [10]
string
str1 = "I@#ma26rt^&ic5us"
Q2. Write a Python program to find numbers divisible by [10]
nineteen or thirteen from a list of numbers using Lambda.
a=[19, 65, 57, 39, 152, 639, 121, 44, 90, 190]
Q3. Find all of the words in a string that are less than 5 letters. [10]
string = "Practice Problems to Drill List Comprehension in
Your Head."
Q4. Calculate income tax for the given income by adhering to the [10]
below rules:
Taxable income Rate (in %)
First $10,000 0
Next $10,000 10
The remaining 20
Expected Output:
For example, suppose the taxable income is 45000 the
income tax payable is:
10000 0% + 10000 10% + 25000 20% = $6000.
Exam on Python Programming
Q5. Given below are the list of positive and negative words. Also, [10]
a list of tweets is provided. Separate out the positive and
negative comments.
positive = ['good','awesome', 'best', 'nice']
negative = ['worst','awful', 'bad']
tweets = ['This government policies are good', 'bad
implementation', 'The way he played showed that he is one
of the best players in the world', 'Her acting in the play was
awesome', 'The wine tastes awful', 'It's nice to hear this little
kid's laugh']
Q6. Extend nested list by adding the sublist. [10]
You have given a nested list. Write a program to extend it by
adding the sublist ["h", "i", "j"] in such a way that it will look
like the following list.
list1 = ["a", "b", ["c", ["d", "e", ["f", "g"], "k"], "l"], "m", "n"]
sub list to add
sub_list = ["h", "i", "j"]
expected output =['a', 'b', ['c', ['d', 'e', ['f', 'g', 'h', 'i', 'j'], 'k'], 'l'],
'm', 'n']
Q7. Remove and add item in a list. [10]
Write a program to remove the item present at index 4 and
add it to the 2nd position and at the end of the list.
list1 = [54, 44, 27, 79, 91, 41]
Q8. Load the iris dataset and Find only those records whose [10]
sepal_length = 5.1 and sepal_width = 3.5
Exam on Python Programming
Q9. Check for Maximum petal_length and convert it in to 7.2 and [10]
min petal_length and convert it in to 1.2
Q10. Perform right join to combine values based on the 'ID' in the [10]
two dataframes.
Use the dataframe given below, read the DataFrame with the
help of clipboard function.
ID Candidate_Name Subject
101 Alex History
102 Amy English
103 Allen Geography
104 Alice German
105 James History
106 Sara German
107 Mia English
ID City Subject_Score
101 Delhi 89
102 Mumbai 78
103 Delhi 77
104 Chennai 87
105 Hyderabad 87
108 Delhi 84