A directory of Objective Type Questions covering all the Computer Science subjects. Here you can access and discuss Multiple choice questions and answers for various compitative exams and interviews.

1. What is the output of the code snippet shown below?
X=”hi”
print(“05d”%X)
a. 00000hi
b. 000hi
c. hi000
d. error
View Answer Report Discuss Too Difficult!
Answer: (d).error

2. Consider the snippet of code shown below and predict the output.
X=”compsci-bits”
print(“%56s”,X)
a. 56 blank spaces before compsci-bits
b. 56 blank spaces before compsci and bits
c. 56 blank spaces after compsci-bits
d. no change
View Answer Report Discuss Too Difficult!
Answer: (a).56 blank spaces before compsci-bits

3. What is the output of the following expression if x=456?
print("%-06d"%x)
a. 000456
b. 456000
c. 456
d. error
View Answer Report Discuss Too Difficult!
Answer: (c).456

4. What is the output of the following expression if X=345?
print(“%06d”%X)
a. 345000
b. 000345
c. 000000345
d. 345000000
View Answer Report Discuss Too Difficult!
Answer: (b).000345

5. Which of the following formatting options can be used in order to add ‘n’ blank spaces after a given string ‘S’?
a. print(“-ns”%S)
b. print(“-ns”%S)
c. print(“%ns”%S)
d. print(“%-ns”%S)
View Answer Report Discuss Too Difficult!
Answer: (d).print(“%-ns”%S)

6. What is the output of this expression if X= -122?
print("-%06d"%x)
a. -000122
b. 000122
c. –00122
d. -00122
View Answer Report Discuss Too Difficult!
Answer: (c).–00122

7. What is the output of the following expression if the value of x is 34?
print(“%f”%x)
a. 34.00
b. 34.0000
c. 34.000000
d. 34.00000000
View Answer Report Discuss Too Difficult!
Answer: (c).34.000000

8. What is the result of the expression shown below if x=56.236?
print("%.2f"%x)
a. 56.00
b. 56.24
c. 56.23
d. 0056.236
View Answer Report Discuss Too Difficult!
Answer: (b).56.24

9. What is the output of this expression if x=22.19?
print("%5.2f"%x)
a. 22.1900
b. 22.00000
c. 22.19
d. 22.20
View Answer Report Discuss Too Difficult!
Answer: (c).22.19

10. The expression shown below results in an error. State whether this statement is true or false.
print("-%5d0",989)
a. True
b. False
c. May be
d. Can't say
View Answer Report Discuss Too Difficult!
Answer: (b).False

Page 1 of 6