Python QB PT1
Python QB PT1
Python QB PT1
PROGRAMS
Use the for loop and elif in a python script that counts and displays all letters,
24 digits and special symbols in a given string
“Python 33345 $_Programming”
Give the output of the following statements if a=10 ,b=1:
i)print(a<<b)
25
ii)print(a>>b)
Note: Practise similar statements on any operators
Analyse the below given python statements and state the output of each statement
if str=”ComputerEngineering”
print(str[:6])
26 print(str[5:4])
print(str[-1:-12:-1])
print(str[::-1])
Note: Similar slicing problems on strings,Lists, tuples may be asked
Use the while loop and write a python program that calculates the sum of numbers
27
in a list.
Write the python script using for loop and range function to get the following output.
28 i) 2 5 8 11 14 17 20 23 26 29
ii) 2 3 4 5
Write a Python function CountFreqList(l) that takes as input a list of integers and
returns a pair of the form (minfreqlist,maxfreqlist) where minfreqlist is a list of
numbers with minimum frequency in l, sorted in ascending order ,maxfreqlist is a
list of numbers with maximum frequency in l, sorted in ascending .
For instance
29 >>> CountFreqList ([13,12,11,13,14,13,7,11,13,14,12])
([7], [13])
>>> CountFreqList ([13,12,11,13,14,13,7,11,13,14,12,14,14])
([7], [13, 14])
>>> CountFreqList ([13,12,11,13,14,13,7,11,13,14,12,14,14,7])
([7, 11, 12], [13, 14])
30 Write a Python script to Search a particular word in a given string.
Write the Python Script that replaces the white spaces with ‘#’ in the given below
31 given string.
str = "Python Programming in academics"
Use the while loop and write a python program that prints the odd numbers in a
32
list.
33 Write a python script to display the calendar of the year 2023.
Write a Python Script to define a class BookStore with constructor that initializes
34 essential attributes. Also calculate total valuation and develop member methods to
update price and quantity of a book. Use array of objects to read data of n books.
SHRI VILE PARLE KELAVANI MANDAL’S
SHRI BHAGUBHAI MAFATLAL POLYTECHNIC
Write a Python script to read data of n students (roll number, name,address and
35 marks of 5 subject) display the data and also percentage of each student. Use
array of object to read and display n students’ information.
Write a Python program to combine two dictionary adding values for common
keys.
36
d1 = {'a': 100, 'b': 200, 'c':300}
d2 = {'a': 300, 'b': 200, 'd':400}
Write a Python program to replace the last value of tuples in a list.
Sample list: [(10, 20, 40), (40, 50, 60), (70, 80, 90)]
37
Expected Output: [(10, 20, 100), (40, 50, 100), (70, 80, 100)]
Write a Python program to calculate the average value of the numbers in a given
tuple of tuples.
Original Tuple:
38
((10, 10, 10, 12), (30, 45, 56, 45), (81, 80, 39, 32), (1, 2, 3, 4))
Average value of the numbers of the said tuple of tuples:
[30.5, 34.25, 27.0, 23.25]
Write a Python script to generate and print a dictionary that contains a number
(between 1 and n) in the form (x, x*x).
39
Sample Dictionary ( n = 5) :
Expected Output : {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
Write a Python program to filter a dictionary based on values.
Original Dictionary:
40 {'Cierra Vega': 175, 'Alden Cantrell': 180, 'Kierra Gentry': 165, 'Pierre Cox': 190}
Marks greater than 170:
{'Cierra Vega': 175, 'Alden Cantrell': 180, 'Pierre Cox': 190}
Write a Python function to reverse a list at a specific location.
Sample Output:
Original list:
41 [10, 20, 30, 40, 50, 60, 70, 80]
Write a Python program to add two given lists of different lengths, starting on the
right.
Sample Output:
42 Original lists:
[2, 4, 7, 0, 5, 8]
[3, 3, -1, 7]
Write a Python script to Check whether given email address contains both ‘@’ and
44
‘.’ symbol or not.
Using in-built python modules write the code snippets for the following:
creation and deletion of folder/directory
display the date in dd-mm-yyyy format
45
display the calendar of “July 2022” month
shuffle the element of given list
Write a Python script to display words having minimum 5 characters and end with
50 ’t’ from the given list of strings