0% found this document useful (0 votes)
5 views

Module 2 Worksheet

The document contains multiple-choice questions, fill-in-the-blank exercises, and programming tasks related to Python programming concepts. It covers topics such as defining functions, operators, comments, and debugging code. Additionally, it includes practical programming questions that require implementing specific functionalities in Python.

Uploaded by

an0450544
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Module 2 Worksheet

The document contains multiple-choice questions, fill-in-the-blank exercises, and programming tasks related to Python programming concepts. It covers topics such as defining functions, operators, comments, and debugging code. Additionally, it includes practical programming questions that require implementing specific functionalities in Python.

Uploaded by

an0450544
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

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. The operator used for floor division is


a) /
b) %
c) //
d) None
Answer:

Q.No.9. 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.10. 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:

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.
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 B 2 + 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

You might also like