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

CH-1 Assignment

The document contains questions related to Python programming concepts like variables, keywords, functions, data types, operators, control flow statements, functions etc. It asks to find the output of code snippets, identify errors, rewrite code after correcting errors, differentiate between data types and more. The questions cover basic to intermediate level Python programming concepts.

Uploaded by

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

CH-1 Assignment

The document contains questions related to Python programming concepts like variables, keywords, functions, data types, operators, control flow statements, functions etc. It asks to find the output of code snippets, identify errors, rewrite code after correcting errors, differentiate between data types and more. The questions cover basic to intermediate level Python programming concepts.

Uploaded by

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

1. Which of the following is not a valid variable name in python? Justify reason for it not being a valid name.

i) 5Radius ii) Radius_ iii) _Radius iv) Radius


2. Which of the following are keywords in python?
i) break ii) check iii) range iv) while
3. Name the Python library modules which need to be imported to invoke the following functions:
i) cos() ii) randint()
4. Rewrite the following code in Python after removing all syntax error(s). Underline each correction done in the
code:
input('Enter a word',w)
if w = 'Hello'
Print('OK')
else:
print('Not OK')
5. Find and write the output of the following Python code:
def ChangeVal(m,n):
for i in range(n):
if m[i]%5 ==0:
m[i] // = 5
if m[i]%3 ==0:
m[i] // = 3
L=[25, 8, 75, 12]
ChangeVal(L,4)
for i in L:
print(i, end='#')
6. Find and write the output of the following Python code:
def Call(P=40, Q=20):
P=P+Q
Q=P-Q
print(P, '@', Q)
return P
R=200
S=100
R=Call(R,S)
print(R, '@', S)
S=Call(S)
print(R, '@', S)
7. Find and write the output of the following python code:
msg = "Technology 2025"
print(msg[3:])
print(msg[:4], msg[4:])
print(msg[::-1])
print(msg[0:4],msg[11:10])
8. Write the names of the immutable data objects from the following:
i) List ii) Tuple iii) String iv) Dictionary
9. If given A=20, B=15, C=30, What will be the output of following expression:
print((A>B) and (B>C) or (C>A))
10. Identify the correct option to print the value 80 from the list L=[10,20,40,80,20,5,55]
(i)L[80] (ii) L[4] (iii) L[L] (iv) L[3]
11. Write a Python statement to declare a Dictionary named ClassRoll with keys as 1, 2, 3 and corresponding values
as "Reena", "Rakesh" and "Zareen" respectively.
12. Which of the options out of (i) to (iv) is the correct data type for the variable Vowels as defined in the following
Python statement: Vowels=('A', 'E', 'I', 'O', 'U')
i) List ii) Dictionary iii) Tuple iv) Array
13. Write the output of the following Python code:
for i in range(2, 7, 2):
print(i * '$')
14. Write the output of the following Python code:
def Update(x=10):
x +=15
print("x = ", x)
x=20
Update()
print("x = ", x)
15. Find the output of following:
colors = ["violet", "indigo", "blue", "green", "yellow", "orange", "red"]
del colors[4]
colors.remove("blue")
colors.pop(3)
print(colors)
16. Differentiate between mutable and immutable objects in Python language with example.
17. Which string method is used to implement the following:
i) To change the first character of the string in capital letter.
ii) To check whether a given character is a letter or a number.
iii) Change one character into other character.
18. Out of the following, find those identifiers, which cannot be used for naming Variables or functions in a Python
program:
Total * Tax, While, Class, Switch, 3rd Row, finally, Column 31, Total.

19. Name the function / method required for:

1. Finding second occurrence of m in madam.


2. get the position of an item in the list.

20. How many times will Python execute the code inside the following while loop? You should answer the question
without using the interpreter! Justify your answers.
i=0
while i < 0 and i > 2 :
print “Hello ...”
i = i+1

21. Rewrite the following for loop into while loop:


for a in range(90, 9, -9):
print(a)
22. How many times is the following loop executed?
for a in range(100,10,-10):
print (a)
23. State True or False – ‘Tuple is one of the datatypes of python having data in key-value pair.”
24. State True or False “Python has a set of keywords that can also be used to declare variables.”

25. What will be the output of the following python expression? print(2**3**2)
26. Observe the given dictionary:
d_std={“Roll_No”:53,”Name”:’Ajay Patel’}
d_marks={“Physics”:84,”Chemistry”:85}
Which of the following statement will combine both dictionaries?
a) d_std + d_marks
b) d_std.merge(d_marks)
c) d_std.add(d_marks)
d) d_std.update(d_marks)
27. What will be the output for the following expression:
not ((False and True or True) and True)
True or not True and False
28. Select the correct output of the following python code:
str=”My program is program for you”
t = str.split(“program”)
print(t)
a) [‘My ‘, ‘ is ‘, ‘ for you’] b) [‘My ‘, ‘ for you’] c) [‘My’,’ is’] d) [‘My’]
29. What will be the output of following expression in python?
print ( round (100.0 / 4 + (3 + 2.55) , 1 ) )
30. What will be the data type of p, if p=(15)?
31. What will the following expression be evaluated to in Python?
print(25//4 +3**1**2*2)
32. Given is a Python string declaration:
message='FirstPreBoardExam@2022-23'
Write the output of: print(message[ : : -3].upper())
33. Predict the output of the following code:
dt=["P",10,"Q",30,"R",50]
t=0
a=""
ad=0
for i in range(1,6,2):
          t = t + i
          a = a + dt [i-1] + "@"
          ad = ad + dt[i]
print (t, ad, a)

34. Predict the output

s="ComputerScience23"
n = len(s)
m=""
for i in range(0, n):
   if (s[i] >= 'a' and s[i] <= 'm'):
        m = m +s[i].upper()
   elif (s[i]>=’n’ and s[i]<=’z’):
        m = m +s[i-1]
   elif (s[i].isupper()):
        m=m+s[i].lower()
   else:
        m=m+’#’
print(m)

35. Rewrite the following code in python after removing all syntax error(s). Underline each correction done in
the code.

Num=int(rawinput("Number:"))
sum=0
for i in range(10,Num,3)
   sum+=1
   if i%2=0:
          print(i*2)
   else:
          print(i*3)
          print (Sum)

36. Vivek has written a code to input a number and check whether it is even or odd number. His code is
having errors. Rewrite the correct code and underline the corrections made.

Def checkNumber(N):
       status = N%2
       return
#main-code
num=int( input(“ Enter a number to check :"))
k=checkNumber(num)
if k = 0:
   print(“This is EVEN number”)
else
   print(“This is ODD number”)

37. Sameer has written a python function to compute the reverse of a number. He has however committed a
few errors in his code. Rewrite the code after removing errors also underline the corrections made.

define reverse(num):
rev = 0
While num > 0:
rem == num %10
rev = rev*10 + rem
num = num/10
return rev
print(reverse(1234))

38. Suppose a tuple T is declared as T = (10, 12, 43, 39), which of the following is incorrect? 

a) print(T[1])  b) T[2] = -29  c) print(max(T))  d) print(len(T))

You might also like