Revision on Python Basics - Assignment, Practical work, CBSE question¶
Topics of importance:
1.Operator precedence
2.For loop
3.While loop
4.If condition
5.Keywords
6.Strings
7.List
8.Tuple
9.Dictionary
10.Jump statement
Practical Question(To be done at the school LAB And to be Written in the PRACTICAL NOTE BOOK)
Q1. Write a program to input Two number form the user and perform the basic arithmetic operation(I.e Addition,Subtraction, multiplication, modulo, floor division and exponent ), display their result to the user
Q2. Generate a four arithmetic operation calculator(I.e +,-,*,/) that can take one operator and two operands, display the result of the operation to the user
Q3. Calculate the factorial of a number using while loop
Q4. Write a python program to input a list and find the maximum, minimum and mean value of the list
Q5. Write a python program to input a string and count the numbers of vowels in the string.
Q6. Write a python program to combine two dictionary adding values for common keys
Input:
d1={‘a’:100, ’b’:200, ’c’:300}
d2={‘a’:300, ‘b’:200, ‘d’:400}
Output should be: {‘a’:400, ‘b’:400, ‘c’:300, ‘d’:400}
Q5. Write a Python program to count the number of characters (character frequency) in a string. Sample String : google.com' Expected Result : {'g': 2, 'o': 3, 'l': 1, 'e': 1, '.': 1, 'c': 1, 'm': 1}
Q6. Write a Python program to count the occurrences of each word in a given sentence.
Q7. Write a Python program to remove duplicate words from a given string.
Sample Output:
Original String:
Python Exercises Practice Solution Exercises
After removing duplicate words from the said string:
Python Exercises Practice Solution
Q8. Write a Python program to get the largest and smallest number from a list.
Q9. Write a Python program to print a specified list after removing the 0th, 4th and 5th elements.
Sample List : ['Red', 'Green', 'White', 'Black', 'Pink', 'Yellow']
Expected Output : ['Green', 'White', 'Black']
Q10. Write a Python program access the index of a list.
Q11. Write a Python program to get the frequency of the elements in a list.
Q12. Write a Python program to change the position of every n-th value with the (n+1)th in a list.
Sample list: [0,1,2,3,4,5]
Expected Output: [1, 0, 3, 2, 5, 4]
Q13. Write a Python script to sort (ascending and descending) a dictionary by value.
Q14. Write a Python script to add a key to a dictionary.
Sample Dictionary : {0: 10, 1: 20}
Expected Result : {0: 10, 1: 20, 2: 30}
Q 15. Write a Python script to check whether a given key already exists in a dictionary.
Q16. Write a Python program to iterate over dictionaries using for loops.
Q17. Write a Python program to remove duplicates from Dictionary.
Q18. Write a Python program to count the frequency in a given dictionary.
Original Dictionary:
{'V': 10, 'VI': 10, 'VII': 40, 'VIII': 20, 'IX': 70, 'X': 80, 'XI': 40, 'XII': 20}
Count the frequency of the said dictionary:
Counter({10: 2, 40: 2, 20: 2, 70: 1, 80: 1})
Q19. Write a Python program to unpack a tuple in several variables.
Q20. Write a Python program to find the repeated items of a tuple.
Q21. Write a Python program to convert a tuple to a dictionary.
Q22. Write a Python program to remove an empty tuple(s) from a list of tuples.
Sample data: [(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')]
Expected output: [('',), ('a', 'b'), ('a', 'b', 'c'), 'd']
Q23. Write a Python program calculate the product, multiplying all the numbers of a given tuple.
Original Tuple:
(4, 3, 2, 2, -1, 18)
Product - multiplying all the numbers of the said tuple: -864
Original Tuple:
(2, 4, 8, 8, 3, 2, 9)
Product - multiplying all the numbers of the said tuple: 27648
Q24. Write a Python program to calculate the average value of the numbers in a given tuple of tuples.
Original Tuple:
((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]
Original Tuple:
((1, 1, -5), (30, -15, 56), (81, -60, -39), (-10, 2, 3))
Average value of the numbers of the said tuple of tuples:
[25.5, -18.0, 3.75]
Q25. Write a python program to terminate a loop on a list of name when the 'guru' name is encountered for the first time.
sample list:
['Siya', 'Tiya', 'Guru', 'Daksh', 'Riya', 'Guru']
output:
Siya
Tiya
Guru
Loop terminated
Q26. Write a python program that traverese over a list of name and prints all the names except "Daksh".
Sample List:
['Siya', 'Tiya', 'Guru', 'Daksh', 'Riya', 'Guru']
Output:
['Siya', 'Tiya', 'Guru', 'Riya', 'Guru']
Q27. Write a python program to demonstrate the usage of "pass" keyword in conditional statement and loops.
Assignment Question(To be done as Homework)
Q1. Write a python program to input a string form the user and count the number of Uppercase and lower case letter in the string.
Q2. Write a program to store students information like admission number, roll number, name and marks in a dictionary and display information on the basis of admission number.
Q3. Write a python program to remove the duplicate from a user input list.
Q4. Write a python program to count the frequency(I.e number of occurrence) of elements in the list.
Q5. Differentiate between mutable and immutable data types
Q6. Write a program to capitalize the first and last letter of each word in a string. The string should be taken as input.
Q7. Write a python program to sort a dictionary by key value
CBSE Question¶
Q1. Out of the following, find those identifiers, which cannot be used for naming Variables or Function in a Python programming:
Price*Oty,class,For,do,4thCol, totally, Row31, _Amount
Q2. Find the invalid identifier from the following:
a)MyName
b)True
c)2ndName
d)My_Name
Q3. Identify the valid identifier from the following:
a) ?
b) <
c) **
d) and
Q4. Which of the following are valid operators in python:
a)*
b)/
c)like
d)||
e)is
f)^
g)between
h)in
Q5.
a) What are data types? How are they important?
b) Write the names of any four data types available in python.
Q6. Rewrite the following code in python after removing all syntax error(s).Underline each correction done in the code:
30=To
for K in range(0,To)
IF k%4==0:
print(K*4)
Else:
print(K+3)
Q7. Write the output of the following Python code:
for i in range(2,7,2):
print(i*'$')