SlideShare a Scribd company logo
Module 2 – Worksheet 1
Multiple Choice Questions
Q.No.1. Which is used to define block of code in python?
a) { }
b) ( )
c) Indentation
Answer:
Q.No.2. Which is used to declare a single line comment?
a) #
b) *
c) //
Answer:
Q.No.3. How to define functions in Python?
a) definition
b) def
c) func
Answer:
Q.No.4. Choose the floor division operator?
a) %
b) /
c) //
Answer:
Q.No.5. Choose the invalid keyword?
a) None
b) FALSE
c) pass
d) break
Answer:
Q.No.6. Choose the correct output for the following Python command: print(0 and 70)
a) 70
b) 0
c) True
d) None
Answer:
Q.No.7. Choose the correct output for the following Expression:
2+(5-4) * 2**10 // 5
a) 206
b) 204
c) -206
d) -204
Answer:
Q.No.8. When passing two arguments V1 and V2 to the function add(int, int) which one of
the following is not correct.
a) def add(V1,V2)
b) def add(V1,V2=7)
c) def add(*V1,V2)
d) def add(V1=5,V2=7)
Answer:
Q.No.9. Choose the output of the following code
def display(v1=6, v2=8):
v2=10
v1=12
print (v1, " ", v2)
display(5,7)
a) 5 7
b) 10 12
c) 12 10
d) 7 5
Answer:
Q.No.10. What is the purpose of the math module in Python?
a) Working with matrices
b) Performing mathematical operations
c) Managing files and directories
d) Handling network communication
Answer:
Fill in the Blanks
Q.No.1. Fill in the blank of the code the program should accept an integer list and it must
print the sum of the biggest and the smallest integer in the list.print( +
)
Hint: numList=list(map(int,input().split()))
Answer:
Q.No.2. ._______________ is the function used to print the ASCII Value of the given
character ch
Hint : Input : g
Output : 103
Answer:
Q.No.3. The program must accept the string S as the input and _____________ should print
the reverse of the given string
Hint : Input : Baseball
Output : llabaseB
Answer:
Q.No.4. The program must accept the price p as the input and it should print the output with
formatting upto 3 decimal places. _______________ statement is used to print the specified
output
Hint : Input : 33.8988
Output : 33.898
Answer:
Q.No.5. Mr. Prakash every day distributed pen (Pen) to the N number of students. The pens
distributed to the students equally and the remaining will be returned to Mr. Prakash.
________________ is used to find the number of pens returned to Mr. Prakash.
Hint : Sample Input1 : 100 Sample Input2 : 123
20 40
Sample Output1 : 0 Sample Output2 : 3
Answer:
Module 2 – Worksheet 2
Rearranging the Python Code
Q.No.1.
def SimpleInt(pr,ti,ra):
simple = (pr * ti * ra)/100
print('The Simple Interest is', simple)
return simple
print('The principal is', pr)
print('The time period is', ti)
print('The rate of interest is',ra)
SimpleInt(Prin, Time, Rate)
Prin = int(input())
Time = int(input())
Rate = int(input())
Hint : Sample Input1 : 7
2
7
Sample Output1 : The principal is 7
The time period is 2
The rate of interest is 7
The Simple Interest is 0.98
Answer:
Q.No.2. Find the Quadratic Equation
a1 = int(input())
b1 = int(input())
c1 = int(input())
import cmath
print('The roots are {0} and {1}'.format(root1, root2))
root1 = (-b-cmath.sqrt(d1))/(2*a1)
d1 = (b1**2) - (4*a1*c1)
root2 = (-b+cmath.sqrt(d1))/(2*a1)
Hint : Sample Input1 : 1
2
1
Sample Output1 : The roots are (-1+0j) and (-1+0j)
Answer:
Q.No.3. Swapping between the numbers without the Third Variable
B= int( input(" Enter B: "))
1. A = int( input(" Enter A: "))
2. A = A - B
3. A = A +B
4. B = A - B
5. print ("B after swapping: ", B)
6. print ("A after swapping: ", A)
Hint : Sample Input1 : Enter A
2
Enter B
4
Sample Output1: A After Swapping: 4
B After Swapping: 2
Answer:
Q.No.4. Converting the decimal Number into Binary
def convertBinary(number):
decimal = int(input())
convertBinary(decimal)
convertBinary(number//2)
if number > 1:
print(number % 2,end = '')
print()
Hint : Sample Input1 : 5
Sample Output1 : 101
Answer:
Q.No.5. Code for Python comparison Operators
a = int(input())
b = int(input())
print("Equal")
print("a == b : ", a==b)
print("Not Equal")
print("a > b : ", a>b)
print("Greater Than")
print("a != b : ",a!=b)
print("Less Than")
print("a <= b : ", a<=b)
print("Greater Than or Equal to")
print("a < b : ", a<b)
print("Less Than or Equal to")
print("a >= b :", a>=b)
Hint : Sample Input1 : 4
5
Sample Output1 : Equal
a == b : False
Not Equal
a != b : True
Greater Than
a > b : False
Less Than
a < b : True
Greater Than or Equal to
a > = b : False
Less Than or Equal to
a < = b : True
Answer:
Programming Questions
Q.No 1 : If the name N of the athlete and the number of medals M won by the athlete in a
games tournament are passed as the input the program must print the message as N Won
M Medals
Hint : Input
Hema
7
Output
Hema Won 5 Medals
Answer:
Q.No 2 : Lakshmi went to saravana hyper market to buy house hold items. 10% discount
was provided by the saravana hyper market when the bill amount BA exceeds 2000. The
amount BA was passed as the input to the program. The Final Payable Amount PA should
printed as output
Hint : Sample Input1 Sample Input2
1900 3000
Sample Output1 Sample Output2
1900 2700
Answer:
Q.No 3 : The Length and Breadth of a rectangle are passed as the input. The program must
calculate the perimeter of the rectangle and print the perimeter as the output. Both the values
are positive integers.
Hint : Sample Input1
20
10
Sample Output1
60
Answer:
Q.No 4: Get three numbers A1, B1,C1 and Calculate the following equation B2
+ 4AC and
print the same.
Hint : Sample Input1
9 15 5
Sample Output1
45
Answer:
Q.No 5 :Two Students have birthdays, they have A and B number of chocolates. The
chocolates have to be distributed among N students in such a way that each student receives
the same number of chocolates and no chocolates are remaining after distribution. If the
chocolates can be distributed as per the given conditions among the N students then print
the number of chocolates each student will receive. The program must print invalid if it cannot
be distributed.
Hint : Sample Input1 Sample Input2
50 40 50 40
30 20
Sample Output1 Sample Output2
3 invalid
Answer:
Module 2 – Worksheet 3
Debugging Code Questions
Q.No 1 : The input of the program was the bottom left coordinates of the square. The side
length of the square also passed as the input. The program should print the top right
coordinates of the square.
botlex = input()
botley = input()
sqlen = input()
toprix = botlex - sqlen
topriy = botley - sqlen
print(toprix)
print(topriy)
Hint: Sample Input1 Sample Input2
0 -10
0 -2
5 7
Sample Output1 Sample Output2
5 -3
5 5
Answer:
Q.No 2 : The integer value Hrs and Mins was passed as the input to the program. The
program must print the total number of seconds in the given hrs and Mins.
Hrs = input()
Mins = input()
Seconds = hrs * 60 / 60 + Mins * 60 * 60
Print(seconds)
Hint: Sample Input1
3
20
Sample Output1
12000
Explanation: 3 Hrs = 10800 + 20 * 60 = 1200 = 12000
Answer:
Q.No 3 : The list of integer was passed as the input to the program. The list should be
appended with the following values as constant (15,25,35) in the end. Then the program
must print all the integers with appended values.
FullList = Fulllist(map(int,input().spllit()))
FullList.Append(element, 15)
FullList.Append(element,25)
FullList.Append(element,35)
Printf(Fulllist)
Hint: Sample Input1
14 17 19
Sample Output1
14 17 19 15 25 35
Answer:
Q.No 4 : The integer N1 was passed as the input to the program. The program must print
average of the following (unit digit, tenth digit and hundred digits of N1) as the output
N1 = input()
Sum =0
Sum = N1/100 + (N1%10) %10 + (N1%100) %10
Avg = Sum/3.0
Print(Avg)
Hint: Sample Input1
4535
Sample Output1
4.333
Answer:
Q.No 5 : The integer N1, M1 was passed as the input to the program. The program must
give the output as the addition of the LSB in the binary representation of N1 and M1.
Note : LSB – Least Significant Bit
N1 = input()
M1 = input()
Print(N1/2 + M1/2)
Hint: Sample Input1
6 7
Sample Output1
1
Explanation: Binary Representation of 6 = 110
Binary Representation of 7 = 111
LSB of 6 + LSB 0f 7 => 0 + 1 => 1
Answer:
Q.No.6.
for i in range(0,21):
if i % 2!=0:
print(i)
What will be the output of the above program
Answer:
Q.No.7. Identify the error?
def print_message()
message = "Hello, Debugging!"
print(message)
print_message()
Answer:
Q.No.8. Identify the error?
def display_number():
print(num)
display_number()
Answer:

More Related Content

PPTX
DOCX
Python Laboratory Programming Manual.docx
PDF
Python for High School Programmers
DOCX
NPTEL QUIZ.docx
PDF
III MCS python lab (1).pdf
PDF
Sample Program file class 11.pdf
PDF
xii cs practicals
PDF
Python Programming
Python Laboratory Programming Manual.docx
Python for High School Programmers
NPTEL QUIZ.docx
III MCS python lab (1).pdf
Sample Program file class 11.pdf
xii cs practicals
Python Programming

Similar to (2 - 1) CSE1021 - Module 2 Worksheet.pdf (20)

PDF
python notes.pdf
PDF
pythonQuick.pdf
PDF
python 34💭.pdf
PDF
XII CS QUESTION BANK FOR BRIGHT STUDENTS CHAPTER WISE SET-II.pdf
PDF
class 12 computer science pdf of class e
PPTX
Python4HPC.pptx
PPTX
Python4HPC.pptx
PDF
Python-Institute.realtests.PCAP.v20q.pdf
PDF
introduction to python programming course 2
PDF
Raspberry Pi - Lecture 5 Python for Raspberry Pi
PDF
python lab programs.pdf
PDF
Computer science sqp
PPTX
python ppt
PDF
pyton Exam1 soln
PPTX
Python basics
PPTX
made it easy: python quick reference for beginners
DOCX
pythonexam.docx
PDF
GE3151 UNIT II Study material .pdf
PPTX
ESCM303 Introduction to Python Programming.pptx
PDF
selfstudys_com_file (4).pdfjsjdcjjsjxjdnxjj
python notes.pdf
pythonQuick.pdf
python 34💭.pdf
XII CS QUESTION BANK FOR BRIGHT STUDENTS CHAPTER WISE SET-II.pdf
class 12 computer science pdf of class e
Python4HPC.pptx
Python4HPC.pptx
Python-Institute.realtests.PCAP.v20q.pdf
introduction to python programming course 2
Raspberry Pi - Lecture 5 Python for Raspberry Pi
python lab programs.pdf
Computer science sqp
python ppt
pyton Exam1 soln
Python basics
made it easy: python quick reference for beginners
pythonexam.docx
GE3151 UNIT II Study material .pdf
ESCM303 Introduction to Python Programming.pptx
selfstudys_com_file (4).pdfjsjdcjjsjxjdnxjj
Ad

Recently uploaded (20)

PPTX
Cell Structure & Organelles in detailed.
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Institutional Correction lecture only . . .
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
01-Introduction-to-Information-Management.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Cell Structure & Organelles in detailed.
Microbial disease of the cardiovascular and lymphatic systems
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Institutional Correction lecture only . . .
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Insiders guide to clinical Medicine.pdf
TR - Agricultural Crops Production NC III.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
01-Introduction-to-Information-Management.pdf
Complications of Minimal Access Surgery at WLH
Final Presentation General Medicine 03-08-2024.pptx
VCE English Exam - Section C Student Revision Booklet
Sports Quiz easy sports quiz sports quiz
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
O5-L3 Freight Transport Ops (International) V1.pdf
RMMM.pdf make it easy to upload and study
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Ad

(2 - 1) CSE1021 - Module 2 Worksheet.pdf

  • 1. Module 2 – Worksheet 1 Multiple Choice Questions Q.No.1. Which is used to define block of code in python? a) { } b) ( ) c) Indentation Answer: Q.No.2. Which is used to declare a single line comment? a) # b) * c) // Answer: Q.No.3. How to define functions in Python? a) definition b) def c) func Answer: Q.No.4. Choose the floor division operator? a) % b) / c) // Answer: Q.No.5. Choose the invalid keyword? a) None b) FALSE c) pass d) break Answer: Q.No.6. Choose the correct output for the following Python command: print(0 and 70) a) 70 b) 0 c) True d) None Answer:
  • 2. Q.No.7. Choose the correct output for the following Expression: 2+(5-4) * 2**10 // 5 a) 206 b) 204 c) -206 d) -204 Answer: Q.No.8. When passing two arguments V1 and V2 to the function add(int, int) which one of the following is not correct. a) def add(V1,V2) b) def add(V1,V2=7) c) def add(*V1,V2) d) def add(V1=5,V2=7) Answer: Q.No.9. Choose the output of the following code def display(v1=6, v2=8): v2=10 v1=12 print (v1, " ", v2) display(5,7) a) 5 7 b) 10 12 c) 12 10 d) 7 5 Answer: Q.No.10. What is the purpose of the math module in Python? a) Working with matrices b) Performing mathematical operations c) Managing files and directories d) Handling network communication Answer:
  • 3. Fill in the Blanks Q.No.1. Fill in the blank of the code the program should accept an integer list and it must print the sum of the biggest and the smallest integer in the list.print( + ) Hint: numList=list(map(int,input().split())) Answer: Q.No.2. ._______________ is the function used to print the ASCII Value of the given character ch Hint : Input : g Output : 103 Answer: Q.No.3. The program must accept the string S as the input and _____________ should print the reverse of the given string Hint : Input : Baseball Output : llabaseB Answer: Q.No.4. The program must accept the price p as the input and it should print the output with formatting upto 3 decimal places. _______________ statement is used to print the specified output Hint : Input : 33.8988 Output : 33.898 Answer: Q.No.5. Mr. Prakash every day distributed pen (Pen) to the N number of students. The pens distributed to the students equally and the remaining will be returned to Mr. Prakash. ________________ is used to find the number of pens returned to Mr. Prakash. Hint : Sample Input1 : 100 Sample Input2 : 123 20 40 Sample Output1 : 0 Sample Output2 : 3 Answer:
  • 4. Module 2 – Worksheet 2 Rearranging the Python Code Q.No.1. def SimpleInt(pr,ti,ra): simple = (pr * ti * ra)/100 print('The Simple Interest is', simple) return simple print('The principal is', pr) print('The time period is', ti) print('The rate of interest is',ra) SimpleInt(Prin, Time, Rate) Prin = int(input()) Time = int(input()) Rate = int(input()) Hint : Sample Input1 : 7 2 7 Sample Output1 : The principal is 7 The time period is 2 The rate of interest is 7 The Simple Interest is 0.98 Answer: Q.No.2. Find the Quadratic Equation a1 = int(input()) b1 = int(input()) c1 = int(input()) import cmath print('The roots are {0} and {1}'.format(root1, root2)) root1 = (-b-cmath.sqrt(d1))/(2*a1) d1 = (b1**2) - (4*a1*c1) root2 = (-b+cmath.sqrt(d1))/(2*a1)
  • 5. Hint : Sample Input1 : 1 2 1 Sample Output1 : The roots are (-1+0j) and (-1+0j) Answer: Q.No.3. Swapping between the numbers without the Third Variable B= int( input(" Enter B: ")) 1. A = int( input(" Enter A: ")) 2. A = A - B 3. A = A +B 4. B = A - B 5. print ("B after swapping: ", B) 6. print ("A after swapping: ", A) Hint : Sample Input1 : Enter A 2 Enter B 4 Sample Output1: A After Swapping: 4 B After Swapping: 2 Answer:
  • 6. Q.No.4. Converting the decimal Number into Binary def convertBinary(number): decimal = int(input()) convertBinary(decimal) convertBinary(number//2) if number > 1: print(number % 2,end = '') print() Hint : Sample Input1 : 5 Sample Output1 : 101 Answer: Q.No.5. Code for Python comparison Operators a = int(input()) b = int(input()) print("Equal") print("a == b : ", a==b) print("Not Equal") print("a > b : ", a>b) print("Greater Than") print("a != b : ",a!=b) print("Less Than") print("a <= b : ", a<=b) print("Greater Than or Equal to") print("a < b : ", a<b) print("Less Than or Equal to") print("a >= b :", a>=b) Hint : Sample Input1 : 4 5
  • 7. Sample Output1 : Equal a == b : False Not Equal a != b : True Greater Than a > b : False Less Than a < b : True Greater Than or Equal to a > = b : False Less Than or Equal to a < = b : True Answer: Programming Questions Q.No 1 : If the name N of the athlete and the number of medals M won by the athlete in a games tournament are passed as the input the program must print the message as N Won M Medals Hint : Input Hema 7 Output Hema Won 5 Medals
  • 8. Answer: Q.No 2 : Lakshmi went to saravana hyper market to buy house hold items. 10% discount was provided by the saravana hyper market when the bill amount BA exceeds 2000. The amount BA was passed as the input to the program. The Final Payable Amount PA should printed as output Hint : Sample Input1 Sample Input2 1900 3000 Sample Output1 Sample Output2 1900 2700 Answer: Q.No 3 : The Length and Breadth of a rectangle are passed as the input. The program must calculate the perimeter of the rectangle and print the perimeter as the output. Both the values are positive integers. Hint : Sample Input1 20 10 Sample Output1 60
  • 9. Answer: Q.No 4: Get three numbers A1, B1,C1 and Calculate the following equation B2 + 4AC and print the same. Hint : Sample Input1 9 15 5 Sample Output1 45 Answer: Q.No 5 :Two Students have birthdays, they have A and B number of chocolates. The chocolates have to be distributed among N students in such a way that each student receives the same number of chocolates and no chocolates are remaining after distribution. If the chocolates can be distributed as per the given conditions among the N students then print the number of chocolates each student will receive. The program must print invalid if it cannot be distributed.
  • 10. Hint : Sample Input1 Sample Input2 50 40 50 40 30 20 Sample Output1 Sample Output2 3 invalid Answer: Module 2 – Worksheet 3 Debugging Code Questions Q.No 1 : The input of the program was the bottom left coordinates of the square. The side length of the square also passed as the input. The program should print the top right coordinates of the square. botlex = input() botley = input() sqlen = input() toprix = botlex - sqlen topriy = botley - sqlen print(toprix) print(topriy) Hint: Sample Input1 Sample Input2 0 -10 0 -2 5 7 Sample Output1 Sample Output2 5 -3 5 5
  • 11. Answer: Q.No 2 : The integer value Hrs and Mins was passed as the input to the program. The program must print the total number of seconds in the given hrs and Mins. Hrs = input() Mins = input() Seconds = hrs * 60 / 60 + Mins * 60 * 60 Print(seconds) Hint: Sample Input1 3 20 Sample Output1 12000 Explanation: 3 Hrs = 10800 + 20 * 60 = 1200 = 12000 Answer:
  • 12. Q.No 3 : The list of integer was passed as the input to the program. The list should be appended with the following values as constant (15,25,35) in the end. Then the program must print all the integers with appended values. FullList = Fulllist(map(int,input().spllit())) FullList.Append(element, 15) FullList.Append(element,25) FullList.Append(element,35) Printf(Fulllist) Hint: Sample Input1 14 17 19 Sample Output1 14 17 19 15 25 35 Answer: Q.No 4 : The integer N1 was passed as the input to the program. The program must print average of the following (unit digit, tenth digit and hundred digits of N1) as the output N1 = input() Sum =0 Sum = N1/100 + (N1%10) %10 + (N1%100) %10 Avg = Sum/3.0 Print(Avg) Hint: Sample Input1 4535 Sample Output1 4.333 Answer:
  • 13. Q.No 5 : The integer N1, M1 was passed as the input to the program. The program must give the output as the addition of the LSB in the binary representation of N1 and M1. Note : LSB – Least Significant Bit N1 = input() M1 = input() Print(N1/2 + M1/2) Hint: Sample Input1 6 7 Sample Output1 1 Explanation: Binary Representation of 6 = 110 Binary Representation of 7 = 111 LSB of 6 + LSB 0f 7 => 0 + 1 => 1 Answer: Q.No.6. for i in range(0,21): if i % 2!=0: print(i) What will be the output of the above program Answer:
  • 14. Q.No.7. Identify the error? def print_message() message = "Hello, Debugging!" print(message) print_message() Answer: Q.No.8. Identify the error? def display_number(): print(num) display_number() Answer: