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

BCSE101E - Computer Programming:

Python

Cycle Sheet – Phase 1 (Module 1 to 5)

School of Computer Science and Engineering


Vellore Institute of Technology
Vellore.
General Instrctions
BCSE101E - Computer Programming:
Python
GNERAL INSTRUCTIONS

1. Computer Programming: Python has two Course Outcomes [CO] which are
mentioned in each question as [CO1] or [CO2]

 Classify various algorithmic approaches, categorize the appropriate data


representation, and demonstrate various control constructs. [CO1]

 Choose appropriate programming paradigms, interpret and handle data using


files to propose solution through reusable modules; idealize the importance of
modules and packages. [CO2]

2. Level of the questions is defined based on Bloom’s taxonomy ([L1], [L2], [L3],
[L4], [L5] and [L6]). It is a hierarchical classification of the different levels of
thinking i.e., basic level to creating new solution level.

3. Students must practice cycle sheet programs in Moodle – Virtual Programming Lab
(VPL) to do the assessments.
 To login for the first time in Moodle:
(Reset the password using Registration number or VIT email id)
BCSE101E - Computer Programming: Python

https://moovit.vit.ac.in/login/forgot_password.php
 Login URL: https://moovit.vit.ac.in/

4. Malpractice in any form is not acceptable and it will be viewed seriously based on
academic guidelines. Students are advised to adhere to the due dates set for each
Assessment.

5. Programs given in Lab Cycle sheet can be used to attain basic knowledge. Cycle
sheet programs are only for practice. Students must explore and practice more
programs which will help to attempt the exams. Challenging problems / Higher order
Thinking [HoT] questions will be asked during Assessments.

1
Module 1 & 2

[M12_CSQ1] Write a problem analysis chart (PAC), Algorithm and flowchart to


calculate the age of a housefly in seconds, given the number of days the housefly
lived. [CO1] [L1]

For example, if a housefly lived for 21 days, then its approximate age in seconds is
21*24*60*60 is 1814400.

Test Cases are

case=1 case=2 case=3


input=21 input:8 input=1
output=1814400 Output=691200 output=86400

[M12_CSQ2] Milk is collected for sales from nearest ‘n’ farms to the milk booth. Given the
amount of milk from ‘n’ farms in liters and ml. Write a PAC chart, algorithm, and flowchart
to compute total quantity of milk in the booth. [CO1] [L1]

BCSE101E - Computer Programming: Python


For example, if milk comes from 3 farms in quantities 2 liters 300 ml, 3 liters 700 ml and 4
liters 600 ml then the total quantity of milk in booth is 10 liters 600 ml.

Test Cases are

case=1 case=2 case=3


input= 2 input= 3 input= 2
2 300 1 100 1 600
3 600 2 200 1 600
output= 5 (in liters) 3 300 output= 3 (in liters)
900 (in ml) output= 6 (in liters) 200 (in ml)
600 (in ml)

2
[M12_CSQ3] Write a PAC Chart, algorithm, and flowchart for converting the given two-
digit number into its corresponding Roman numeral [CO1] [L1]

Test Cases are

case=1 case=2 case=3

input=20 input:21 input=25

output=XX Output=XXI output=XXV

[M12_CSQ4] Write a PAC Chart, Algorithm and Python program to input two complex
numbers and add the same to produce the result. After producing the result, print the real
part and imaginary part separately. [CO1] [L1]

Test Cases are

case=1 case=2 case=3


input= 10+10j input= 10 input= 10j
20+20j 20+10j 1+1j
output= 30+30j output= 30+10j output= 1+11j
Real Part is 30 Real Part is 30 Real Part is 1
Imaginary Part is 30 Imaginary Part is 10 Imaginary Part is 11
BCSE101E - Computer Programming: Python

[M12_CSQ5] Write a PAC Chart, Algorithm and Python program to convert the given
integer to the corresponding binary, octal and hexadecimal values and print the same.
[CO1] [L1]

Test Cases are

case=1 case=2 case=3


input=106 input=98 input=9
output=0b1101010 output=0b1100010 output=0b1001
0o152 0o142 0o11
0x6a 0x62 0x9

3
[M12_CSQ6] Write a PAC Chart, Algorithm and Python program to calculate the area of a
triangle, given its three sides a, b, and c. [CO1] [L1]

Test Cases are

case=1 case=2 case=3


input=5 6 7 input=3 7 5 input=10 12 15
output=14.70 output=6.50 output=59.81

[M12_CSQ7] Write a PAC chart, algorithm, and Python program to convert string to
integer. [CO1] [L1]

Test Cases are

case=1 case=2 case=3


input=’10’ input=’123’ input=’1345’
output=10 output=123 output=1345

[M12_CSQ8] Write a PAC chart, algorithm, and Python program to convert integer to
string. [CO1] [L1]

Test Cases are

BCSE101E - Computer Programming: Python


case=1 case=2 case=3
input=10 input=123 input=1345
output=’10’ output=’123’ output=’1345’

[M12_CSQ9] Write a PAC Chart, algorithm, and Python program to convert Fahrenheit to
Celsius by using lambda operator. Print the result with two decimal places only. [CO1][L1]

Test Cases are

case=1 case=2 case=3


input=106 input=98 input=100
output=41.11 output=36.66 output=37.77

4
[M12_CSQ10] Write a PAC chart, algorithm, and Python program to swap the value of the
given two variables. [CO1][L1]

Test Cases are

case=1 case=2 case=3


input=10 20 input=120 128 input=100 325
output=20 10 output=128 120 output=325 100

Module 3

[M3_CSQ1] Draw a flowchart and construct a python program to accept the monthly
income of an employee and display the income tax to be paid at the end of the year
according to the following criteria : [CO1] [L2]

Annual income (in Rs) Income Tax

> 1000000 4%

> 500000 and <= 1000000 2%

<= 500000 NIL


BCSE101E - Computer Programming: Python

Test Cases are

case=1 case=2 case=3


input=95000.00 input=1000000.00 input=1200000.00
output=0 output=20000 output=48000

[M3_CSQ2] Draw a flowchart and construct a python program to A taxi driver charges the
bill as follows. On a fine day, Mr. Roy travels to his office by the taxi. Write a Python
program to accept the kilometers travelled by Mr. Roy and calculate his taxi bill. [CO1] [L2]

5
First 10 Km Rs15/km
Next 90 Km Rs 8/km
After that Rs6/km

Test Cases are

case=1 case=2 case=3


input=7 input=50 input=120
output=105 output=470 output=990

[M3_CSQ3] Draw a flowchart and construct a python program to for the course BCSE101E,
bonus marks are awarded to the students according to their mark scored in the exam and
the class type. Write a python program to accept the marks, class type ‘T’ for theory or ‘L’
for lab. Display the final marks by adding the bonus mark to the original mark, based on
the given conditions. [Note: If the mark given by the user is 0 then display the message:
“Enter appropriate Mark”]. [CO1] [L2]

Bonus
Mark Class type
Mark %
>=80 T 8%
L 6%
>= 60 and <80 T 6%
L 4%
>=40 and <60 T 4%

BCSE101E - Computer Programming: Python


L 2%
<40 T 0%
L 0%
Test Cases are

case=1 case=2 case=3


input=92.0 input=55.0 input=0
T L output=Enter the appropriate mark
output=99.36 output=56.1

[M3_CSQ4] Draw a flowchart and construct a python program to receive a positive


number n, then computes the factorial of all the even numbers between 1 and n, if the

6
given n is an even number. Same way the factorial of odd numbers between 1 and n if the
given n is an odd number. (use while loop) [CO1] [L2]

Test Cases are

case=1 case=2 case=3


input=5 input=6 input=-2
output=1 1 output=2 4 output=Enter the
3 6 4 24 positive number
5 120 6 720

[M3_CSQ5] Draw a flowchart and construct a python program to calculate sum of digits of
a given number until the sum becomes a single digit number. (Using loop). [CO1] [L2]

Test Cases are

case=1 case=2 case=3


input=234 input=967 input=2347
output=9 output=4 output=7

Module 4
BCSE101E - Computer Programming: Python

[M4_CSQ1] Draw a flowchart and construct a python program to accept a list of N


numbers. The job is to determine if there exists an element in the list such that the sum of
the elements on its left is equal to the sum of the elements on its right. If such element
exists, then print the index of the element. If there are no such elements, then the sum is
zero. [CO1] [L2]

Sample workout for better understanding as given below

7
Input:
6 // length of list
[4, 3, 100, 2, 3, 2] //actual list
Output:
2 (index of the chosen element) (Sum of elements at the left = Sum of elements at the
Right = 7)
Test Cases are

case=1 case=2 case=3


input=6 input=5 input=3
4 3 100 2 3 2 8 1 4 3 1 1 6 4 1
output= 2 output= 1 output=0

[M4_CSQ2] Draw a flowchart and construct a python program to Write a python program
using list to implement reverse polish notation calculator. In reverse polish notation,
mathematical expressions are written with the operator following its operands. For
example, 3 + 4 becomes 3 4 +. Order of operations is entirely based on the ordering of the
operators and operands. To write 3 + (4 ∗ 2), we would write 3 4 2 ∗ + in RPN. The
expressions are evaluated from left to right. Evaluate the expression and display the result.
[CO1] [L2]

For a sample workout as given below:

BCSE101E - Computer Programming: Python


Input:
5 // length of list
["2","1","+","3","*"] //actual list
Output:
9

Test Cases are

case=1 case=2 case=3


input=9 input=5 input=7
5 1 2 / 4 * + 3 - 2 1 + 3 * 2 4 1 * - 9 *
output=4 output=9 output=-18

8
[M4_CSQ3] Draw a flowchart and construct a python program to Write a Python program
to create and accept a two-dimensional list of M elements with different data types. Use
this list as a database to store two entries (rows) and retrieve the appropriate row by
assuming some field as primary key. [CO1] [L2]

Sample workout as given below:

Input:
2 //Number of lists
5 // length of list M
[“John”, “smith”, 1234, “B+”, 10.03] //actual list row1
[“Rockey”, “Jr”, 6789, “A+”, 40.03] //actual list row2
2 // index of the primary key
1234 //value of the primary key query

Output:
[“John”, “smith”, 1234, “B+”, 10.03]

Test Cases are

case=1 case=2 case=3


BCSE101E - Computer Programming: Python

input=2 input=2 input=2


5 5 5
“John” “smith” “Ron” “smith” 123 “Ron” “smith” 123
1234 “B+” 10.03 ”B+” 10.03 ”B+” 10.03
“Rockey” “Jr” 6789 “key” “Mr” 679 “key” “Mr” 679
“A+” 40.03 “A+” 40.03 “O+” 40.03
2 2 3
1234 679 O+
output=[“John”, output=[“key”, “Mr”, output=[“key”, “Mr”,
“smith”, 1234, “B+”, 679, “A+”, 40.03] 679, “O+”, 40.03]
10.03]

9
[M4_CSQ4] Draw a flowchart and construct a python program which accepts the items of
tuples containing the category as the first entry and different components of the category
along with their costs as the following entries. The job is to create a tuple which
summarizes the costs for each category. [CO1] [L2]

Sample workout as given below:


Input:
2 //No of tuples
7 //No of items in 1st tuple
Education //Items in the 1st tuple Category
Primary // Component
50 //Cost
Secondary
25
Higher
20
7 //No of items in 2nd tuple
Defense //Items in the 2nd tuple Category
Army //Component
25 //Cost
AirForce
40
Navy
45

Output:
((Education, 95), (Defense, 110))
Test Cases are

BCSE101E - Computer Programming: Python


case=1 case=2 case=3
input =3 input=2 input=1
5 7 1
Stationary Education Expenditure
marker Primary
80 50 output=
chalk Secondary ((Expenditure, 0))
10 25
3 Higher
Communication 20
phone 7
250 Defense
5 Army
Internet 25

10
Airtel AirForce
100 40
Jio Navy
80 45
output=((Stationary, output=((Education,
90), (Communication, 95), (Defense, 110))
250), (Internet, 180))
[M4_CSQ5] Draw a flowchart and construct a python program to read the three subject’s
marks secured by n students during FAT examination. If a student secured less than 50 in
any subject, the student is failed in that subject. Count the number of students who failed
in each subject and the total number of students who failed in at least one subject. [CO1]
[L2]

Sample Workout as given below:

Input:

S1 = {'m1': 50, 'm2': 40, 'm3':75}

S2 = {'m2': 49, 'm3': 35, 'm4':54}

S3 = {'m1': 77, 'm2': 84, 'm4':51}

Output:

{'m1': 0, 'm2': 2, 'm3': 1, 'm4': 0}

Test Cases are


BCSE101E - Computer Programming: Python

case=1 case=2 case=3


input=3 input=2 input=2
3 3 3
M1 M1 M1
50 50 90
M2 M2 M2
40 51 10
M3 M3 M3
75 49 50
3 3 3
M2 M1 M1
49 60 70
M3 M4 M2
35 20 30
M4 M5 M3

11
54 50 40
3
M1 output= output=
77 M1 M1
M2 0 0
84 M2 M2
M4 0 2
51 M3 M3
1 1
output= M4 2
M1 1
0 M5
M2 0
2 2
M3
1
M4
0
2

Module 5

BCSE101E - Computer Programming: Python


[M5_CSQ1] Construct an algorithm and write a python program for the problem given
below:

You have been given a String S consisting of uppercase and lowercase English alphabets.
You need to change the case of each alphabet in this String. That is, all the uppercase
letters should be converted to lowercase and all the lowercase letters should be converted
to uppercase. You need to then print the resultant String to output. [CO2] [L2]

Input Format
The first and only line of input contains the String S
Output Format
Print the resultant String on a single line.

12
Test Cases are

case=1 case=2 case=3


input= abcdE input= SAKTHI input= John Peter
output= ABCDe output= sakthi output=jOHN pETER

[M5_CSQ2] Construct an algorithm and write a python program for the problem given
below: [CO2] [L2]

A word is called as a good word if all the letters of the word are distinct. That is, all the
letters of the word are different from each other letter. Else, the word is called as a bad
word. Write an algorithm and the subsequent Python code to check if the given word is
good or bad.: e.g. START, GOOD, BETTER are bad: WRONG is good! Make the comparison
to be case insensitive.

Test Cases are

case=1 case=2 case=3


input= Apple input= FALL input= FAN
output= BAD output= BAD output=GOOD

[M5_CSQ3] Construct an algorithm and write a python program to search a literal, string
in a string and find the location within the original string where the pattern occurs. [CO2]
[L2]
BCSE101E - Computer Programming: Python

Test Cases are

case=1 case=2 case=3


input= The quick input= The quick input= The quick brown
brown fox jumps over brown fox jumps over fox jumps over the lazy
the lazy dog the lazy dog dog
Fox lazy down

output= 16 to 19 output= 35 to 39 output=Not found

[M5_CSQ4] Construct an algorithm and write a python to create a regular expression to


retrieve marks and names from a given string or files. Extract only marks having 2 digits
and names starting with capital letter. [CO2] [L2]

13
A word is called as a good word if all the letters of the word are distinct. That is, all the
letters of the word are different from each other letter. Else, the word is called as a bad
word. Write an algorithm and the subsequent Python code to check if the given word is
good or bad.: e.g. START, GOOD, BETTER are bad: WRONG is good! Make the comparison
to be case insensitive.

Test Cases are

case=1 case=2 case=3


input= Rahul got 75 input= Guru got 95 input= Mani got 75 marks,
marks, Vijay got 55 marks, Sivaji got 95 Poya got 55 marks, whereas
marks, whereas Subbu marks, whereas Rajini Suresh got 98 marks from
got 98 marks got 98 marks. gopinath.

output= ['75', '55', '98'] output= ['95', '95', '98'] output=['75', '55', '98']
['Rahul', 'Vijay', 'Subbu'] ['Guru', 'sivaji', 'Rajini'] ['Mani', 'Poya', 'Suresh']

[M5_CSQ5] Construct an algorithm and write a python program python program to create
a regular expression to retrieve all words starting with vowels in each string. [CO2] [L2]

Test Cases are

case=1 case=2 case=3


input= An apple for a day input= Actions speak input= Everyone wants to

BCSE101E - Computer Programming: Python


keeps the doctor away louder than words. go to heaven, but nobody
wants to die.
output= An output= Actions
apple output= Everyone
away

14

You might also like