Python Mega Assignment # 1
Python Mega Assignment # 1
X = [ 9,2,8,4,5]
X__?__
print (X)
Output: [2,8,4,5]
1) .delete(9)
2) .rm(9)
3) .remove(9)
13. p = 3
q = 'hello! '
print( q __?__ p)
1) *
2) **
3) +
print (y__?__)
1) .upper()
2) .upcase()
3) .capitalize()
15. p = True
q = ‘True’
r=2
r = 2.0
print(type(p))
print(type(q))
print(type(r))
print(type(s))
1) q and R2
2) p and R2
3) p and R1
4) R1 and q
1) X(p)
2) p$x()
3) X().p
4) p.x()
18. X=4 , Y= 2
print(X % Y)
print(X / Y)
print(X // Y)
print(Y % X)
for i in __?__:
for j in __?__:
Output: 4
for i in __?__:
for j in __?__:
Output: 4 5
1 9
1 0
for i in __?__:
for j in __?__:
Output: 4 1 1 5 9 0
for i in __?__:
for j in __?__:
Output: 4 1 1
5 9 0
Item 1 – 16.14
Item 2 – 6.45
Item 3 – 17.11
1) z
2) i
3) j
4) x
5) k
6) y
D = dict()
for j in range(2):
D[i] = j
a. {0: 1, 1: 1, 2: 1}
b. {1: 0, 1: 1, 1: 2}
c. {0: 1, 1: 2, 2: 3}
d. {1: 2, 1: 1, 1: 0}
23. You are writing a function that increments player score in a soccer game
Once a parameter is defined with default value, any parameter to the right must also be defined
with default values (True or False)
def avg ( x , y , z = 50 ):
adding = x + y + z
avg_value = adding / 3
return avg_value
y = avg ( x = 5 , y = 9 , z = 20 )
print(y)
25. What will be output? Describe it with reason and logic behind. Do multiple experiments with
arguments / parameters to remove error, if occurs.
26. Final output is not required. Just take copy pencil, think and write the output of each line, write
down the link between parameters and arguments. Remove one or two ** from other_info and
observe the ouput.
27. The position of parameters and arguments is re-arranged. Just think and find the logic behind
output or error.
def display_result(winner, **other_info, score):
28. What will be the output of the following Python expression if X=123?
print(“%06d”%X)
a) 123000
b) 000123
c) 000000123
d) 123000000
29. What will be the output of the following Python expression if x=22.19?
print("%5.2f"%x)
a) 22.1900
b) 22.00000
c) 22.19
d) 22.20
a) Error
b) ‘1.234560, 1.22345, 1.23’
c) No output
d) ‘1.234560, 1.234560, 01.23’
31. Write down the output of each line after each iterations. Do multiple experiments to change values
i=1
while False:
if i%2 == 0:
break
print(i)
i += 2
32. Write down the output of each line after each iterations. Do multiple experiments to change values
x = "abcdef"
i = "a"
while i in x:
x = x[:-1]
33. Write down the output of each line after each iterations. Do multiple experiments to change values
for i in ''.join(reversed(list('abcd'))):
print (i)
34. Flow of the program. Write the output of each line after every iteration of ‘i’
for i in range(10):
if i == 5:
break
else:
print(i)
else:
print("Here")
35. What is the output? And understand the functionality of lambda function
y=6
z = lambda x: x * y
print z(8)
36. Write output and give proper logic of whatever the output comes.
i=0
def change(i):
i=i+1
return i
change(1)
print(i)
40. What will be output? Define this output clearly
print(type(two))
print(two)
change(1,2,3,4)
print(type(b))
find('letters',A='1',B='2')
42. Write output and define each line’s output for each iteration of ‘i’
x.append(i)
return x
for i in range(3):
print(foo(i))
43. Evaluate the following Python arithmetic expression: and write which segment will execute first?
(Brackets, Exponents, Multiplication, Addition / Subtraction, Left to right rule)
44.You are creating a function that manipulates a number. The function has the following requirements:
A. math.fmod(x)
B. math.frexp(x)
C. math.floor(x)
D. math.ceil(x)
E. math.fabs(x)
45. You are writing code that generates a random integer with a minimum value of 5 and a maximum
value of 11.
Which two functions should you use? Each correct answer presents a complete solution. (Choose two.)
A. random.randint(5, 12)
B. random.randint(5, 11)
C. random.randrange(5, 12, 1)
D. random.randrange(5, 11, 1)
46. Write a program that receives marks from user and check the grade.