0% found this document useful (0 votes)
266 views5 pages

CSE101 Midterm Exam Monsoon2019

The document contains instructions and questions for a midterm exam in CSE-101 Introduction to Programming. It has 9 multiple part questions worth a total of 20 marks and allocates 60 minutes to complete the exam. Students are instructed to use Python3 and that all questions are mandatory. No doubts will be discussed during the exam.

Uploaded by

Yash Tanwar
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)
266 views5 pages

CSE101 Midterm Exam Monsoon2019

The document contains instructions and questions for a midterm exam in CSE-101 Introduction to Programming. It has 9 multiple part questions worth a total of 20 marks and allocates 60 minutes to complete the exam. Students are instructed to use Python3 and that all questions are mandatory. No doubts will be discussed during the exam.

Uploaded by

Yash Tanwar
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/ 5

CSE-101, Introduction to Programming

Midterm Exam, 2019


Marks: 20 Time: 60 minutes
Name: __________________ Roll Number: ____________________
Section: _________________ Group: _________________________

Instructions:
1. Assume the use of Python3 in all of the questions below.
2. All questions are mandatory.
3. No doubts will be discussed during the exam.

Q1) [1 + 1 = 2 Points] Code:  Q2) [1 + 1 + 1 = 3 Points] Write the output


x = "IP A" #1  of the following? In case of error, what
x[-1] = "B"  #2  error the program does have?
y = "EASY_CSE101-SecB" #3 
y[-2] = "C" #4 
y[-3] = "E" #5  a. Code: 
print(y[5:-8]+x[-2:1]+x[0:2]+y[12:-1]+x[2:])#6  x = "CSEIP" + 1 
print(x) 
 
i) [1 Point] Indicate the lines which will throw  
error. Explain why.  
 
b. Code: 
x = "CSEIP" 
print(x[5]) 
 
 
 
 
 
ii) [1 Point] Write the output of Line 6 if all the c. Code 
error prone lines are removed. x = "123456" 
print() 
y = "abcdef" 
 
print(y[int(x[2])]) 
 
Q3) [1 + 2 = 3 Points] Code:  Q4) [2 Points]​ ​What will be the output if
a = 2  the below code is run?
b = 1 
def f1(a, b): 
Code​: 
c = a * b 
a = 1 
c = c - 5 
b = 2 
c = c / 3 
c = 3 
print(type(c)) 
d, e = 4, 5 
return c 
if a == 1: 
  
print("Yes") 
def f2(a, b): 
if b == 2: 
b = b * 3 
print("No") 
a = a + b * 4 + 4 
elif c == 3: 
b = 100 
print("YesNo")  
d = a / 5 
if d == 4: 
e = b // 5 
print("Yes") 
return e 
if e == 5: 
  
print("YesYes")  
if a == 2: 
else: 
print(f1(a, b)) 
print("NoNoNo") 
if b == 1: 
print(f2(a, b))

i) [1 Point] How many output lines will show up


when the code is run on python console?

ii) [2 Point] What is the output?


Q5) [2 Points] Write the output of the following Q6) [2 + 1 = 3 Points] Fill in the blanks:
code.
i) [1 + 1 = 2 Points] Complete the function
class Point: 
redact so that it meets the specifications.
def __init__(self,a,b): 
def redact(s): 
self.x=a 
 
self.y=b 
"""Returns: a copy of string s where 
  all but the first and last letter have 
  been replaced by 3 x's. If s contains 
a = Point(1,2)  fewer than 3 characters, returns a copy 
def f(a):  of s.  
a.x=a.x + 1   
print("f() ", a.x)  Precondition: s contains only lowercase 
letters; it may be empty. 
return a 
 
def g(a): 
Examples:  
f(a)  'apple' -> 'axxxe'  
a = 2  'banana' -> 'bxxxa'  
a += -1  'preliminary' -> 'pxxxy'  
print('g() ', a)  'a' -> 'a'  
return a  """  
def h(a):   
n=len(s)  
a.y = a.y + 3.0 
if(________________________): #1 
print('h() ', a.y) 
return s  
a = f(a)  else:  
a.y += g(a)  return _______________ #2 
return a   
   
final = h(a)   
print(final.x)   
 
print(final.y) 
 
 
 
 
 
ii) [1 Point] Assign a value to x so that
character ‘A’ is printed out:

x=_______  
if(x%2==0 and x%5==3):  
print(‘A’) 
Q7) [2 Points] Write a function lucky_sum(a,b,c) that given 3 int values a, b and c,
return their sum. However, if one of the values is 13 then it does not count
towards the sum and the values to its right count only if they are even.

Example:
lucky_sum(1, 2, 3) → 6 lucky_sum(1, 2, 13) → 3 lucky_sum(1, 13, 3) → 1
lucky_sum(13, 1, 2) → 2 lucky_sum(13, 4, 2) → 6 lucky_sum(13, 5, 21)→0

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Q8) [1 Point] Give an example code of one line that when run would result into a
name error. 
 
 
 
 
 
 
 
Q9) [2 Points] Consider the below code. Give the maximum number of frames the
code will have at any point of time in the stack space. Show each function call
with the argument value passed to it.
 
def f(a): 
if a == 1 or a == 0: 
return 6 
else:  
return f(a-1) + f(a-2) 
 
print(f(3)) 
 
 
 
 
 
 
 
 

 
 

You might also like