Professional Documents
Culture Documents
NewxiiAB Cs I Miidterm 2425
NewxiiAB Cs I Miidterm 2425
NewxiiAB Cs I Miidterm 2425
General Instructions:
Section –A
Q No. Question Marks
1. State True or False (R)
“ converts one data type into another data type automatically in
python” (1)
2. which of the following is an invalid data type in python?(U) (1)
(a) List (b) Tuple (c) Dictionary (d) Value
3. What will the following code do? ( U)
dict={“phy”:94,”che:70,”Bio”:82,”Eng”:95}
dict.update((“che”:72,”Bio”:80))
(a) It will create new dictionary as
dict={che”:72,”Bio”:80} and old dict will be deleted
(b) It will throw and error ad dictionary cannot be updated
(c) It will simply update the dictionary as
dict={“phy”:94,”che”:72,”Bio”:80,”Eng”:95}
(1)
(d) It will not throw any error but it will not do any changes in
dict.
4. Consider the given expression: (U)
True and False or True and not True
Which of following will be correct output if the given
expression is evaluated?
(a) True
(b) False (1)
(c) NONE
(d) NULL
5. Select the correct output of the following string operation ?
str="my name is Anu John" (A) (1)
print(str.capitalize( ))
(a) ‘My name is anu john’
(b) Type Error: Unsupported operand type(s) for ‘str’
(c) ‘My name is Anu John’
(d) ‘My Name is Anu john’
6 Which of the following statement(s) would give an error after (1)
executing the following code? (A)
SECTION – B
11. (a) predict the output of (U) (1+1)
S=”Pythonlanguag”
print(S[:-6:-2])
d={2:”b”,4:”c”}
d1={1:”a”}
d.update(d1)
d[1]=”v”
print(list(d.values()))
12. Write any two string operators and give examples (R) (2)
13. Predict the output of the following code? (A) (2)
def my_func(a=10,b=30):
a+=20
b-=10
return a+b,a-b
print(my_func(a=60)[0],my_func(b=40)[1])
SECTION – D
SECTION – E
19. Rewrite the following code in python after removing all syntax (4)
error(s). Underline each correction done in the code (A)
Value =30
for VAL in range(0,Value)
If val%4==0:
print (VAL*4)
Elseif val %5==0:
print(VAL+3)
Else
print(VAL+10)
21 Find the program code given below, Identify the parts mentioned (5)
below: (CB)
def processNumber(x):
x=72
return x+3
y=54
res=processNumber(y)
identify the parts: Function header, Function call
arguments, parameters, and Function body
22. Traffic accident occur due to various reasons. While problems (5)
with roads or inadequate safety facilities lead to some accidents,
majority of the accidents are caused by drivers’ carelessness and
their failure to abide by traffic rules. (CB)
ITS Roadwork is a company that deals with manufacturing and
installation of traffic lights so as to minimize the risk of accidents.
Keeping in view the requirements, traffic simulation is to be
done.
Write a program in python that simulates a traffic light. The
program should perform the following.
(a) A user-defined function trafficLight() that accept from the
user , display an error message if the user enters anything
other the RED, YELLOW and GREEN. Function light( )
Is called and the following is displayed depending upon
return value from light():
(i) “STOP. Life is more important than speed” if the
Value returned by light() is 0.
(ii) ”PLEASE GO SLOW” if the value returned by
light() is 1.
(iii) “you may go now” if the value returned by light( ) is 2.