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

Python Question Bank-10-TERM1PAPER

This document contains a Python question bank about strings and loops. It includes 43 multiple choice questions testing various concepts like valid for loop syntax, string manipulation methods like capitalize() and title(), string slicing, immutability, and loop types like while and for loops. Sample code is provided to predict output for tasks like string concatenation, indexing, slicing, and more.

Uploaded by

Kavin C Krishnan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
342 views

Python Question Bank-10-TERM1PAPER

This document contains a Python question bank about strings and loops. It includes 43 multiple choice questions testing various concepts like valid for loop syntax, string manipulation methods like capitalize() and title(), string slicing, immutability, and loop types like while and for loops. Sample code is provided to predict output for tasks like string concatenation, indexing, slicing, and more.

Uploaded by

Kavin C Krishnan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Python Question Bank-Strings & Loops

Grade - X
I. Choose the correct answer:
1. Which of the following is a valid for loop in Python?
(a) for(i=0; i < n; i++) (b) for i in range(0,5):
(c) for i in range(0,5) (d) for i in range(5)

2. In the following example, how many times will the loop run?
i=2
while(i>0):
print(i)
i=i-1
(a) 2 (b) 3
(c) 1 (d) 0

3. What will be the output of the following Python code?


for i in range(0,2,-1):
print("Hello")
(a) Hello (b) Hello Hello
(c) Error (d) No Output

4. Strings are immutable in Python, which means a string cannot be modified.


(a) True (b) False
(c) Error (d) None of the above

5. Which method should I use to convert String "welcome to the world of python" to
"Welcome To The World Of Python".
(a) capitalize() (b) title()
(c) find() (d) None of the above

6. Which of the following sequences would be generated in the given line of code?
for i in range(5,0,-2):
print(i)
(a) 5 4 3 2 1 0 -1 (b) 5 4 3 2 1 0
(c) 5 3 1 (d) None of the above

7. A while loop in Python is used for what type of iteration?


(a) Indefinite (b) Discriminant
(c) Definite (d) Indeterminate

8. Guess the correct output for the following string operations:


str2="welcome"
print(str2*3)
(a) welcomewelcome (b) welcomewelcomewelcome
(c) welcome (d) TypeError

9. When does the else statement written after loop executes?


(a) When break statement is executed in the loop
(b) When loop condition becomes false
(c) Else statement is always executed
(d) None of these
10. What will be the output of the following code?
x = "abcd"
for i in range(len(x)):
print(i)
(a) abcd (b) 0 1 2 3
(c) 1 2 3 4 (d) a b c d

11. What will be the output of the following code?


x = 12
for i in x:
print(i)
(a) 1 2 (b) 12
(c) Error (d) None of these

12. Predict the correct output of the following String operations:


str1 = 'Welcome'
print (str1[:6] + 'NPSKengeri')
(a) Welcom NPSKengeri (b) Welcome NPS Kengeri
(c) WelcomNPSKengeri (d) WelcomeNPSKengeri

13. Choose the correct function to get the ordinal number of a character in Python.
(a) ascii('a') (b) char('a')
(c) ord('a') (d) None of these

14. What is the output of the following string operations?


Str1 = "My salary is 50000";
print(str1.isalnum())
(a) False (b) True
(c) Error (d) None of these

15. Which of the following is False?


(a) String is immutable.
(b) capitalize() function in string is used to return a string by converting the whole
given string into uppercase.
(c) lower() function in string is used to return a string by converting the whole given string
into lowercase.
(d) None of these

16. What will be the output of the below code?


str1="Information"
print(str1[2:8])
(a) format (b) formation
(c) orma (d) ormat

17. What will be the output of below Python code?


str1="Application"
str2=str1.replace('a','A')
print(str2)
(a) application (b) Application
(c) ApplicAtion (d) application
18. What will the below python code return?
str1="save paper,save plants"
print(str1.find("save"))
(a) It returns the first index position of the first occurrence of "save" in the given
string str1.
(b) It returns the last index position of the last occurrence of "save" in the given string str1.
(c) It returns the last index position of the first occurrence of "save" in the given string str1.
(d) It returns the first index position of the last occurrence of "save" in the given string str1.

19. What will the following Python code return?


str1="Stack of books"
print(len(str1))
(a) 13 (b) 14
(c) 15 (d) 16

20. The character that must be at the end of the line for if, while, for blocks.
(a) : (b) ;
(c) , (d) None of these

21. Loop executed for a fixed number of times with a built-in counter.
(a) while loop (b) for loop
(c) Repeat loop (d) if else

22. Which term describes a loop that continues repeating without a terminating (ending)
condition?
(a) Conditional loop (b) Unconditional loop
(c) Sequence loop (d) Infinite loop

23. What keyword would you use to add an alternative condition to an if statement?
(a) else if (b) elseif
(c) elif (d) None of the above

24. What would be the output of the following code?


Mali = 5
print("Mali" + " is " + str(Mali))
(a) Mali is Mali (b) Mali is 5
(c) 5 is Mali (d) 5 is 5

25. What would be the output of the following code?


s = "python is awesome"
print(s[2] + s[-5])
(a) te
(b) tw
(c) o
(d) Error, you cannot use the [ ] operator with the + operator

26. For loop in Python is:


(a) Entry loop (b) Exit loop
(c) Simple loop (d) None of these
27. In which of the following loop in Python, we can check the condition?
(a) for loop (b) while loop
(c) do while loop (d) None of the above

28. Predict the output for the following code snippet:


x = "abcdef"
i = "i"
while i in x:
print(i, end=" ")
(a) no output (b) i i i i i…
(c) a b c d e f (d) abcdef

29. What would be the output of the following code?


>>> sub="help"
>>> str1="helping hand"
>>> sub2="HELP"
>>> sub in string
(a) False (b) True
(c) Error (d) None of these

30. What would be the output of the following code?


s="Hello"
print(s[5:10])
(a) Index Error (b) Empty String
(c) No output (d) None of these

31. Predict the output of the following code:


'1.0'.isnumeric()
(a) True (b) False
(c) Error (d) None of these

32. What would be the output of the following code?


'This is great'.split(' ')
(a) [this is great] (b) (This is great)
(c) ['This', 'is', 'great'] (d) None of these

33. Can an integer be added to a string in Python?


(a) No (b) Yes
(c) May be (d) None of these

34. Predict the output for the following code:


>>> str='Sami sells sea shells by the sea shore'
>>> str.replace('sea', 'mountain')
(a) 'Sami sells sea shells by the sea shore'
(b) 'Sami sells mountain shells by the mountain shore'
(c) 'Sami sells mountain shells by the sea shore'
(d) All of these

35. What is the output of the following code?


>>> 'once upon a time'.title()
(a) 'Once Upon A Time' (b) 'Once upon a time'
(c) 'ONCE UPON A TIME' (d) None of these

36. What will be the output of the following code?


str1='Python'
print(str1[2:])
(a) ython (b) thon
(c) Python (d) All of these

37. Predict the output for the following code:


txt = "Hello World"
print(txt[::-1])
(a) dlroW olleH (b) olleH dlroW
(c) elrowolleH (d) None of these

38. Predict the output for the following code:


str1='amazing'
print(str1[-7:-3])
(a) zing (b) amaz
(c) azing (d) None of these

39. Predict the output for the following code:


str2='NPS Kengeri'
print(str2[:5])
(a) NPS K (b) Kengeri
(c) NPS Ke (d) None of these

40. Which of the following is a string operator?


(a) in (b) *
(c) + (d) All of these

41. Accessing the individual characters of a string through unique index of each character is
known as _________________.
(a) String Traversing (b) String Transferring
(c) String concatenation (d) None of these

42. What will be the output of the following code?


print('ab'.isalpha())
(a) False (b) True
(c) Error (d) None

43. Predict the output for the following code:


st1="String Slicing"
print(st1[:])
(a) String Slicing (b) Slicing
(c) stringslicing (d) None of these

44. _______________ keyword is used in Python to place a space after the displayed string
instead of a newline.
(a) '\t' (b) '\n'
(c) end (d) None of these
45. Predict the output for the following code:
s='My'
s1='Blog'
s2=s[:1]+s1[len(s1)-1:]
print(s2)
(a) mg (b) Mg
(c) MB (d) Yg

46. How many times will the loop run?


i=2
while(i>0):
print(i)
i=i-1
(a) 2 (b) 3
(d) 1 (d) 0

47. What will be the output for the following code?


for i in range(0,2,-1):
print("Hello")
(a) Hello (b) Hello Hello
(c) No output (d) Error

48. Which of the following loop is not supported by the Python programming language?
(a) for loop (b) while loop
(c) do while loop (d) None of the above

49. Which of the following loop is work on the particular range in Python?
(a) for loop (b) while loop
(c) do while loop (d) recursion

50. Predict the output for the following code:


while(1):
print(2)
(a) 2 (b) Infinite loop
(c) 1 (d) None of the above

*****

You might also like