Revision Assignment computer science
Revision Assignment computer science
Revision Assignment computer science
S.NO. QUESTIONS
3. Which of the following functions will return the last three characters of a strings?
(a) s[3 : ] (b) s[ : 3]
(c) s[-3 :] (d) s[: -3]
6. Which of the following functions will return the string with every ‘P’ replaced with
a ‘z’?
(a) find() (b) index()
(c) replace() (d) split()
1. str1="Aplication"
str2=str1.replace('a','A')
print(str2)
2.
str1="poWer"
str1.upper()
print(str1)
4. str="hello wolrd"
str*3
S = "PURA VIDA"
1. print(S[9] + S[9 : 15])
2. S1 = S[: 10] +S[10 :]
print(S1)
3. S2 = S[10] + S[-10]
print(S2)
5. Which of the following is not an immutable type in Python?
a. string
b. tuple
c. set
d. list
6 In Python, a variable must be declared before it is assigned a value.
a. True
b. False
c. Only in function
d. Only in modules
7 For two objects x and y, the expression x is y will yield True, if and only if
a. id(x)==id(y)
b. len(x)==len(y)
c. x==y
d. All of these
8 In python, a variable may be assigned a value of one type, and then later assigned a
value of a different type. This concept is known as:
a. mutability
b. static typing
c. dynamic typing
d. immutability
9 What will the following code produce?
a=8.6
b=2
print(a//b)
a. 4.3
b. 4.0
c. 4
d. compilation error
10 Fill in the blanks:
1. The explicit conversion of an operand to a specific type is called __________.
2. Identifiers, literals, string, tuples, sets are all ________.
3. To increase the value of x five times using an augmented assignment
operator, the correct expression will be __________
4. The result of the expression 10 or 0 will be ___________.
5. The result of the expression 'x' and 'a’ will be_____________.
6. Boolean data type is internally treated as_________ data type.
7. The floor division of two integers yields a result of _________ type.
8. The __________ datatype is like lists but is not mutable.
9. To use function fabs( ) _________module should be imported..
10. To generate a random integer in a range, _________ or
____________ function is used.
11 Figure out the problem with the following code fragment. Correct the code.
s1='must'
s2='try'
n1=12
n2=3
print(s1+s2)
print(s2*n2)
print(s1+n1)
print(s1*s2)
12 Write the output of the following:
a=7;b=-4;c=30;d=-12
a+b+c>a+c-b*d
print(str(a+b+c>a+c-b*d)==str(True))
13 What will be following code print?
str1 = '''Hell
o'''
print(len(str1))
str2 = '''Hell\
o'''
print(len(str2))
print(len(str1) > len(str2))
14 Given str1 = "Hello", what will be the values of:
(a) str1[0]
(b) str1[1]
(c) str1[-5]
(d) str1[5]
15 What is the output of the following code?
str1 = "Mission 999"
str2 = "999"
print(str1.isdigit(),str2.isdigit())
str = "My roll no. is 12"
print(str.isalnum())
str1 = 'Waha'
print(str1[:3] + 'Bhyi' + str1[-3:])
16 Write following expressions in Python:
(a) 1/3πr2h
−b+ √ b 2−4 ac
(b) x=
2a
17 Consider the code given below:
a. import random
r = random.randrange(100, 999, 5)
print(r, end = ' ')
r = random.randrange(100, 999, 5)
print(r, end = ' ')
r = random.randrange(100, 999, 5)
print(r)
b. import random
r = random.randint(10, 100) - 10
print(r, end = ' ')
r = random.randint(10, 100) - 10
print(r, end = ' ')
r = random.randint(10, 100) - 10
print(r)
c. import statistics as st
v = [7, 9, 8, 12, 6,6]
m1 = st.mean(v)
m2 = st.mode(v)
m3 = st.median(v)
print(m1, m2, m3)
18 True/False Questions
Question 1
Strings have both positive and negative indexes.
Question 2
Python does not support a character type; a single character is treated as strings of
length one.
Question 3
Strings are immutable in Python, which means a string cannot be modified.
Question 4
Like '+', all other arithmetic operators are also supported by strings.
Question 5
Functions capitalize() and title() return the same result.
Question 6
The find() and index() are similar functions.
19 Write a Python script that traverses through an input string and prints its
characters in different lines — two characters per line.
Write a program which replaces all vowels in the string with '*'.
Write a program that inputs a line of text and prints out the count of vowels in it.
Write a program to input a line of text and print the biggest word (length wise)
from it.
20 Explain following string functions with examples:
1. "Hello World".lower( )
2. "Hello World".upper( )
3. "Hello World".find("Wor", 1, 6)
4. "Hello World".find("Wor")
5. "Hello World".find("wor")
6. "Hello World".isalpha( )
7. "Hello World".isalnum( )
8. "1234".isdigit( )
9. "123FGH".isdigit( )