Assignment Unit I & Ii: Part-A
Assignment Unit I & Ii: Part-A
UNIT I & II
MCA II Semester
PROGRAMMING IN PYTHON
Subject Code:- MCA144B
Part-A
Part-B
1. [CO1] Read radius of a circle and side of a square from user using single input()
method. Then calculate and display area of the circle and the square.
Input: 3.33 3.33
Output: Area of circle: 34.82 Area of square: 11.09
2. [CO1]Write a program that reads names of two python files and strips the extension.
The filenames are then concatenated to form a single string. The program then prints
'True' if the newly generated string is palindrome, or prints 'False' otherwise.
Input: malay.py aLam.py Output: True
3. [CO1] WAP in python to find the difference b/w ASCII code of any lowercase letter
and its corresponding uppercase letter. (EXAMPLE b-B 98-68= 32)
4. [CO1] Translate the following algo into python code
Step 1: Initialise variable name pound with value 10.
Step 2: multiply pound by 0.45 & assign it to a variable KG
Step 3: Display the value of variables
5. [CO1] Write a program in python to reverse a 4 digits number by using // floor division
operator and % module operator also print the sum of all digits.
6. [CO2] Write a program in python to read two numbers from the users. display the result
using bitwise operator.
7. [CO2] Write a program to read the marks of 5 subject through the keyboard find out
the aggregate and percentage of marks assume maximum marks that can be obtained
by a student in each subject 100.
8. [CO2] Write a program that reads full name as a input and returns abbreviations of the
first and middle names except the last name. Note that the abbreviations must be in
capitals. Also, only the first letter in the Surname must be in higher case.
Eg. Input: Sachin Ramesh Tendulkar Output: S. R. Tendulkar
9. [CO2] WAP in python to print the sum of numbers from 1 to 100 (1 and 100 are also
included) which are not divisible by 2,3 or 5.
10. [CO2] Write a program that first reads a piece of text entered by a user, and then reads
a key. The program should display a frequency with which the key has occurred in the
piece of text.
TEST CASE:- Input:
Can you write a whole paragraph without letter a? I wouldn't recommend it.
Honestly, your sentences will sound wrong. Not just you but everyone else to o
will notice you are doing something weird. You will use uncommon words. It's
not worth the effort involved.
Will Output: The will count is: 3
Part-C
1. [CO1] Consider Str1,Str2,Str3,Str4- the four different strings given as:-
Str1 = “Welcome to Python Programming”
Str2 = “Welcome to Python Programming”
Str3 =Str1
Str4 = “to”
What are the results of the following expressions??
len(Str1) e) Str1[5:10]
Str1[-7] f) Str1.count(‘m’)
Str1[-3-1] g) Str1[8].capitalize()
Str3==Str1 h) Str1 + “ ” + Str1
2. [CO1] Write a Python function that prints out the first n rows of Pascal's triangle.
Input: N = 5 Output:
1
11
121
1331
14641
3. [CO1] Display pattern with using looping statement :-
1
1 2
1 2 3
1 2 3 4
1 2 3
1 2
1
4. [CO1] Consider a scenario where a son eats 5 chocolates every day. the price of each
chocolate is different. his father pays the bill to the chocolate vendor at the end of every
week. develop a program that can generate the bills for the chocolate and send to the
father, also state which loop will be used to solve this program.
5. [CO1] WAP to convert hexadecimal no. as a string into equivalent binary format.
6. [CO2] Write the function countVowels(word) which takes a word as an argument and
returns the vowels ('a', 'e', 'i', 'o', 'u') in that word.
Test Case:- Input:- Word = I love python programming
Output :- {'u':0, 'i':2, .....}
7. [CO2] WAF is_Lst_Palindrome(Lst) to check whether a list is Palindrome it should
return True/False.
Testcase: Lst = [1,2,3,2,1] output:- True
Lst = [1,2,3] output:-False.
8. [CO2] Consider a list with a mixed type of elements such as
L1=[1,’x’,4,5.6,’z’,9,’a’,0,4]. Create another list using list comprehension which
consists of only the integer element present within the L1.
9. [CO2] Write a program to perform following tasks: - Read a list of integers from a user.
- Remove duplicate values from this list. We call it a super list. - In a single scan of the
super list, perform following operations: - If the number is not perfectly divisible by 3,
discard it. - If the number is greater than 30, add 5 to it. Else, subtract 5 from it. - Display
contents of the list.
Testcases:
Input Output
5 80 66 3 70 80 5 [71, -2]
0 0 77 8 3 99 [-5, -2, 104]
10. [CO2] A course instructor wants to compute overall GPA of a student based on his
performance in the whole semester. Maximum GPA is 10. To evaluate a student, the
instructor follows the policy as shown below:
Exam Maximum Marks Weightage
Quiz 1 20 5%
Mid Sem 50 20%
Quiz 2 20 5%
End Sem 100 30%
Lab Work 100 20%
Project 50 20%
Write a program that reads marks got by a student in all 6 exams and based on the policy
shown above computes the GPA.
Note: Limit the float value till two decimal points.
Input: 20 40 18 80 90 45 Output: 8.55
Part-D
1. [CO2] Write a program that reads a positive integer and then displays the following
pattern.
Input: Input:
3 5
Output: Output:
----c---- --------e--------
--c-b-c-- ------e-d-e------
c-b-a-b-c ----e-d-c-d-e----
--c-b-c-- --e-d-c-b-c-d-e--
----c----- e-d-c-b-a-b-c-d-e
--e-d-c-b-c-d-e--
----e-d-c-d-e----
------e-d-e------
--------e-------
2. [CO1] Write a program to check if the given year is a leap year or not.
Use following guidelines to decide whether a year is leap year or not:
- The year can be evenly divided by 4, is a leap year, unless: The year can be evenly
divided by 100, it is NOT a leap year, unless: The year is also evenly divisible by 400.
Then it is a leap year.
- The program should read year from a user.
- The year should be passed to a method is_leap_year() as an argument.
- The method should return a Boolean value.
- Print the value returned by the method.
Testcases:
Input Output
2024 True
4025 False
2900 False
3. [CO2] Write a program that reads number of rows and prints following pattern:
TEST CASE 1 TEST CASE 2
Input: 3 Input: 5
1 1
2 1 21
4 2 1 421
8421
16 8 4 2 1
4. [CO1] Write a program to compute GPA, given marks of all six exams.
A course instructor further wants to use GPA of a student to assign grade
as follows:
GPA Grade
10 O
9+ A
8+ B
7+ C
6+ D
5.5+ Pass
0+ Fail
Extend the program you have written yesterday to assist the instructor in assigning
grades to students. The program should read marks of all 6 exams and then print the
GPA and/or the grade, as per the case.
Follow the guidelines:
- The program should be menu-driven:
Menu:
(A) Compute GPA
(B) Assign Grade
(Q) Quit
- Read choice from the user as a letter 'A', 'B', 'Q'
- If the choice is A:
-Read marks of all 6 exams are entered by a user at once, separated with a single space.
-The program should check if the marks entered for each exam are not exceeding
maximum marks.
- Compute and print the GPA.
- If the choice is B:
- Read GPA entered by a user and print the grade.
Testcases:
Input Output
10 O
5.5 Pass
7.444 C
EXAMPLE :-
Menu:
(A) Compute GPA
(B) Assign Grade
(Q) Quit
Enter your Choice: A
20 40 18 80 90 45
8.55