Suggested Python Programs For Summer Assignment - I

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

CLASS XII | COMPUTER SCIENCE (083)

LIST OF SUGGESTED PYTHON PROGRAMS

Following programs are suggestive practice problems to develop proficiency in Python programming.
Assume that A, B, M, N are natural numbers and X, Y are float type numbers and S & W are Strings.

1. Define a function Pattern(N) to display the following pattern when N=4:


1
212
32123
4321234
Write a program to display this pattern for N=5.

2. Define a function isPalindrome(N) to check whether N is a Palindromic number or not. If


Palindrome, the function should return 1 otherwise 0. Using the defined function, write a
program to display all Palindromic numbers between 1 and 1000.

3. Define a function isPrime(N) to check whether N is a prime or not. If prime, the function should
return 1 otherwise 0. Using the defined function, write a program to display all prime numbers
between 1 and 100.

4. Define a function HCF(A,B) to calculate and return the HCF/GCD of the numbers A and B.
Using the defined function, write a program to check whether two user inputted M and N are
co-prime or not.

5. Define a function SumOfFactors(N) to calculate and return sum of all proper factors of N (all
factors including 1 and excluding the number N itself). Using the defined function, write a
program to check whether a number M is perfect or not.

6. Define a function SumOfFactors(N) to calculate and return sum of all proper factors of N (all
factors including 1 and excluding the number N itself). Using the defined function, write a
program to check whether 2 numbers A and B are amicable or not.

7. Define a recursive function Factorial(N) to calculate and return factorial of N. Write a program
to display factorial of the first 5 natural numbers.

8. Define a recursive function Fibonacci(N) to calculate and return N th member of the Fibonacci
number series. Write a program to display the first 20 Fibonacci numbers.

9. Define functions Pow(X,N) and Factorial(N) to calculate and return XN and N! respectively.
Using the defined function, write programs to calculate and display the sum of following series:
10. Define a function Encode(W) which encode a word (group of characters) as follows:

i) Lower case alphabets are changed into upper case alphabets and vice versa.
Characters other than alphabets remains unchanged.
ii) First character is swapped with the second character, third with the fourth character,
and so on. In case of odd number of characters, last character remains unchanged.

Write program which will read a sentence from the user and display the encrypted sentence
after encoding all words.

11. Define a function isPalindrome(W) to check whether W is a Palindromic word or not.


Create a List SENTENCES of 5 sentences entered by the users. Using the defined function,
display all Palindromic words present in the 5 sentences.

12. Define a function CountWord(S, W) to count and return number of occurrences of the word W
in the sentence S.
Create a List SENTENCES of 5 sentences entered by the users. Using the defined function,
count total number of occurrences of the word ‘Modern’ in the 5 sentence stored in SENTENCES.

13. Create a List SENTENCES of 5 sentences entered by the users and display the followings:
All words starts with ‘A’ or ‘a’ and size more than 4 characters
All words ends with ‘A’ or ‘a’ and size less than 4 characters
All sentences starts with alphabets ‘A’ or ‘a’

14. Write a menu based program to perform the following task on a Python List NUMBERS.

A sample List NUMBERS = [12, 33, 13, 54, 34, 57]

The tasks are:


i) Add a new number in the List NUMBERS, entered by the user
ii) Display all numbers stored in the List NUMBERS
iii) Sort the List NUMBERS in descending order using bubble sort technique (define a function).

15. Write a menu based program to perform the following task on a Python List WORDS.

A sample List WORDS = ['LAN', 'MAN', 'WAN', 'VoIP', 'HTTPS']

The tasks are:


i) Add a new word in the List WORDS, entered by the user
ii) Display all words stored in the List WORDS
iii) Sort the List WORDS alphabetically using Insertion sort technique (define a function).
16. Define a function LSearch(ARR,DATA)to check whether the List of numbers ARR contains the
searched number DATA or not using Linear Search Technique. If DATA found in the List ARR,
the function should return 1 otherwise 0.

A sample List NUMBERS = [12, 13, 33, 34, 54, 57]

If DATA = 54, the function should return 1 and


If DATA = 44, the function would return 0

Write a program to check the correctness of the function with the sample values of NUMBERS
and DATA.

17. Define a function bSearch(ARR,DATA)to check whether the List of numbers ARR contains the
searched number DATA or not using Binary Search Technique. If DATA found in the List ARR,
the function should return 1 otherwise 0.

A sample List NUMBERS = [12, 13, 33, 34, 54, 57]

If DATA = 54, the function should return 1 and


If DATA = 44, the function would return 0

Write a program to check the correctness of the function with the sample values of NUMBERS
and DATA.

18. Write a menu (and function) based program to perform the following tasks on a Python List
STUDENTS storing name and marks of few students having the following structure and
implemented as a Stack based on LIFO operations.

A sample List STUDENTS=[['Raghav',89],['Rohan',90],['Amrita',91]]

The tasks are (based on LIFO):


i) Add a new student in the List STUDENTS, name and marks entered by the user
ii) Display all Student’s Names and their Marks from the List STUDENTS
iii) Remove a student from the List STUDENTS. Also display the content of the removed
student. If removal/deletion is not possible, specify the reasons.

19. Write a menu (and function) based program to perform the following tasks on a Python List
PERSONS storing name and age of few persons having the following structure and
implemented as a Queue based on FIFO operations.

A sample List PERSONS=[['Rahamat',18],['Rajeev',19],['Amos',17]]

The tasks are (based on FIFO):


i) Add a new person in the List STUDENTS, name and age entered by the user
ii) Display all person’s Names and their Age from the PERSONS List
iii) Remove a person from the List PERSONS. Also display the content of the removed
person. If removal/deletion is not possible, specify the reasons.
20. Define a function Separate(NUMBERS) to accept a python Tuple NUMBERS containing natural
numbers as a formal argument and creates and returns two separate Tuples EVEN and ODD
depending upon whether the numbers in tuple are even or odd as explained below:

A sample Tuple NUMBERS = (12, 33, 13, 54, 34, 57)


The separated Tuples are:
EVEN = (12, 54, 34)
ODD = (33, 13, 57)

The tasks are:


i) Add a new entry in the Tuple NUMBERS, entered by the user
ii) Display all entries stored in the Tuple NUMBERS
iii) Separate the Tuple NUMBERS using the defined function and display the two newly
created Tuple EVEN and ODD

21. Define a function GRADES(EMPLOYEES) to accept a Python dictionary EMPLOYEES as a


formal argument and creates and returns two separate dictionaries GradeA and GradeB
depending upon whether the values(Salary) are more than 25000 or not as explained below:

A sample Dictionary EMPLOYEES = {'John':18000,'Rahim':24000,'Anita':31000}


The separated Dictionaries are:
GradeA = {'Anita':31000}
GradeB = {'John':18000,'Rahim':24000}

The tasks are:


iv) Add a new entry in the Dictionary EMPLOYEES, entered by the user
v) Display all entries stored in the Dictionary EMPLOYEES
vi) Separate the Dictionary EMPLOYEES using the defined function and display the two
newly created Dictionaries GradeA L and GradeB.

22. Define a function FREQTable(T) which accepts a Tuple T, having few natural numbers. The
function creates a Dictionary FT to store the frequency table of individual numbers in the Tuple
T. Function finally returns the Dictionary FT.

If T=(4,2,6,2,4,2,4,2)
The function should return FT={4:3,2:4,6:1}

Write a minimal program to use the defined function effectively.

23. Define a function FREQTable(S) which accepts a string S, having a sentence of few words.
The function creates a Dictionary FT to store the frequency table of individual words in the
sentence STR. Function finally returns the Dictionary FT.
Note: While creating FT, ignore the space.

If STR= 'INDIANA'
The function should return FT={'I':2, 'N':2, 'D':1, 'A':2}

Write a minimal program to use the defined function effectively.


PYTHON-MySQL CONNECTIVITY PROGRAMMING (ALL 5 PROGRAMS ARE COMPULSORY):

1. Address Book – Solve the following:


 Define a function to create a MySQL Table(Relation) having following Columns(Attributes):
 Name
 Phone
 Email
 Define a function to append some records into the table
 Define a function to search for a record in the table – search by name
 Define a function to modify a record – search by name
 Define a function to remove/delete a record from the table – search by name
 Write a menu based complete program to combine all the function defined above.

2. Blood Donor’s Database


 Design a MySQL Table(Relation) having following Columns(Attributes) of some volunteer
Blood Donors:
 AadhaarNo
 BloodGroup
 LDD # Last Date of Donation in dd/mm/yyyy format
 Name
 DOB # Date of Birth in dd/mm/yyyy format
 Address
 District
 State
 Country
 MobileNo1
 MobileNo2
 Email
Your program should have at least the following user friendly options:
 Create the Table & Add New Donor
 Search a Donor by Blood Group
 Modify details of a Donor
 Remove a donor from the file

Write complete menu based Python - MySQL connectivity program using Table (Relation)
having suggsted Columns (Attributes) like the previous two programs,to solve the
following problems:
3. Software for a Bank # AccNo, CName, AadhaarNo, PhoneNo, BalanceAmt
File operations must include – Open a New Account, Withdrawal, Deposit

4. Inventory of a Store # PID, PName, Descriptions, SCode, MStock, CStock, Price, LDU # Last Date of Update
File operations must include – Open a New Account, Search and Display Acc. details, Withdrawal, Deposit

5. MCQ Quiz # QID, Question, OptionA, OptionB, OptionC, OptionD, Answer [A/B/C/D]
File operations must include – Add Questions, Modify Questions, Remove Questions, Play Quiz
SUGGESTIONS FOR REAL LIFE BASED GAMES USING RANDOM NUMBERS (any TWO):

1. Number Sequencing Game.


2. 2 Dices Game.
3. Tic-Tac-Toe Game.
4. Scrabble Game.
5. Hollywood Game.

CRATE YOUR OWN MODULE:

Create your own module DATAANALYSIS by defining the following functions:

i) Define a Function to return Length of ARR = Len(ARR)


ii) Define a Function to return Min of ARR = Min(ARR)
iii) Define a Function to return Max of ARR = Max(ARR)
iv) Define a Function to return Range of ARR = Range(ARR)
v) Define a Function to return sorted List of ARR = Sort(ARR)
vi) Define a Function to return Mean of ARR = Mean(L)
vii) Define a Function to return Median of ARR = Median(ARR)
viii) Define a Function to return Dictionary FT={0:3,1:2,2:3,,,,,,,5:1} of ARR
ix) Define a Function to return Mode of ARR = Mode(ARR)
x) Define a function to return Mean deviation about M for ARR = MDM(ARR,M)
xi) Define a function to return Mean deviation about Mean for ARR = MDMean(ARR)
xii) Define a function to return Mean deviation about Median for ARR = MDMedian(ARR)
xiii) Define a function to return Mean deviation about Mode for ARR = MDMode(ARR)
xiv) Define a Function to return Variance of ARR = Var(ARR)
xv) Define a Function to return SD of ARR = SD(ARR)

Write a python program to import your own module and check all your functions for a List (and also
for a Tuple) DICE having 10 random numbers between 1 to 6 (both inclusive)

You might also like