[go: up one dir, main page]

0% found this document useful (0 votes)
65 views6 pages

Assignment Unit I & Ii: Part-A

This document contains a 20 question assignment on Python programming concepts. It is divided into 3 parts - Part A contains 14 multiple choice questions testing basic Python concepts like keywords, data types, functions, operators etc. Part B contains 6 programming questions asking to write Python code to solve problems related to input/output, strings, mathematical operations etc. Part C contains 5 programming questions and 5 multiple choice questions related to lists, loops, functions and other Python concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views6 pages

Assignment Unit I & Ii: Part-A

This document contains a 20 question assignment on Python programming concepts. It is divided into 3 parts - Part A contains 14 multiple choice questions testing basic Python concepts like keywords, data types, functions, operators etc. Part B contains 6 programming questions asking to write Python code to solve problems related to input/output, strings, mathematical operations etc. Part C contains 5 programming questions and 5 multiple choice questions related to lists, loops, functions and other Python concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

ASSIGNMENT

UNIT I & II
MCA II Semester
PROGRAMMING IN PYTHON
Subject Code:- MCA144B

Part-A

1. [CO1] All keywords in Python are in _________


a) Capitalized b) lower case c) UPPER CASE d) None of the mentioned
2. [CO2] Which of the following functions can help us to find the version of python that
we are currently working on?
a) sys.version(1) b) sys.version(0) c) sys.version() d) sys.version
3. [CO1]What is the maximum possible length of an identifier?
a) 31 characters b) 63 characters
c) 79 characters d) none of the mentioned
4. [CO1] Which of the following results in a Syntax Error?
a) ‘”Once upon a time…”, she said.’ b) “He said, ‘Yes!'”
c) ‘3\’ d) ”’That’s okay”’
5. [CO2] What is the output of following code:
>>> list1=[['a','b','c'],[1,2,3,4],['Maxx','Ted','Sam'],1,2,3]
>>> list1[1].pop(1)
a) 2 b) [1,2,3,4] c) ERROR d) 3
6. [CO1] What is the output of the following code : >>>9//4
a) 2 b) 2.2 c) 2.0 d) ERROR
Which one of the following is not attributes of file?
a) closed b) soft space c) rename d) mode
7. [CO2] What will be the output of the following Python code?
def test(i,j):
if(i==0):
return j
else:
return test(i-1,i+j)
print(test(4,7))
a) 13 b) 7 c) Infinite loop d) 17
8. [CO2] What will be the output of the following Python code?
def f(x, y, z):
return x + y + z
f(2, 30, 400)
a)432 b)24000 c)430 d) No output
9. [CO2] Lambda function contains block of statements.
a) True b) False
10. [CO2] What will be the output of the following Python code?
i=1
while True:
if i%3 == 0:
break
print(i)
i+=1
a) 1 2 3 b) error c) 1 2 d) none of the mentioned
11. [CO1] What will be the output of the following Python code snippet if x=1?
x<<2
a) 4 b) 2 c) 1 d) 8
12. [CO1] What are the values of the following Python expressions?
2**(3**2)
(2**3)**2
2**3**2
a) 512, 64, 512 b) 512, 512, 512 c) 64, 512, 64 d) 64, 64, 64
13. [CO2] What will be the output of the following Python code?
l=[1, 0, 2, 0, 'hello', '', []]
list(filter(bool, l))
a) [1, 0, 2, ‘hello’, ”, []] b) Error
c) [1, 2, ‘hello’] d) [1, 0, 2, 0, ‘hello’, ”, []]
14. [CO1] Which of the following is the use of id() function in python?
a) Every object doesn’t have a unique id b) Id returns the identity of the object
c) All of the mentioned d) None of the mentioned
15. [CO2] What will be the output of the following Python function?
min(max(False,-3,-4), 2,7)
a) -4 b) -3 c) 2 d) False
16. [CO2] Which of the following results in a Syntax Error?
a) ‘”Once upon a time…”, she said.’ b) “He said, ‘Yes!'” c) ‘3\’ d)”’That’s okay”’
17. [CO1] What will be the output of the following Python expression if x=56.236?
print("%.2f"%x)
a) 56.236 b) 56.23 c) 56.0000 d) 56.24
18. [CO2] What will be the output of the following Python function?
len(["hello",2, 4, 6])
a) Error b) 6 c) 4 d) 3
19. [CO1] What does pip stand for python?
a) Pip Installs Python b) Pip Installs Packages
c) Preferred Installer Program d) All of the mentioned
20. [CO1] Which module in the python standard library parses options received from the
command line?
a) getarg b) getopt c) main d) os

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

You might also like