O String and List: Topics: Program 1. Numeric Difference (Strings)
O String and List: Topics: Program 1. Numeric Difference (Strings)
Now, Numeric difference among two words "raghu" and "college" is 55-59 =
-4
Input Format
Constraints
Assume both the strings will have only lower case alphabets
Output Format
Sample Input 0
raghu
college
Sample Output 0
-4
Sample Input 1
rec
rei
Sample Output 1
-6
Test cases
raghu -4
college
rec -6
rei
hagsdkfigwieuy 29
kuhweiufv
iwgeif -19
hyvw
MCQs
1. Which of the following is True regarding loops in Python?
A. Loops should be ended with keyword "end".
B. No loop can be used to iterate through the elements of strings.
C. Keyword "break" can be used to bring control out of the current loop.
D. Keyword "continue" is used to continue with the remaining statements inside the
loop.
Ans: C
2. How many times will the loop run?
i=2
while(i>0):
i++
A. 2
B. 3
C. Infinite times
D. error
Ans: D
3. What will be output?
a=10
b=10
if a is b:
print("Yes")
else:
print("No")
A. No output
B. Error
C. Yes
D. No
Ans:C
5.
Given the nested if-else below, what will be the value x when the code executed
successfully
x = 0
a = 7
b = 6
if a > 0:
if b < 0:
x=x+5
elif a > 5:
x=x+4
else:
x=x+3
else:
x = x + 2
print(x)
A. 0
B. 4
C. 3
D. 2
Ans: B
6. Which of the following Python code will give different output from the others?
A. for i in range(-5,-2):
print(i)
B. for i in [-5,-4,-3]:
print(i)
C. for i in range(-5,-2,1):
print(i)
D. for i in range(-5,-2,-1):
print(i)
Ans: D
8. When you execute a break command inside the inner loop of a pair of nested
loops ...
A. ...both the inner loop and the outer loop are interrupted.
B. ... the inner loop is interrupted and the outer loop is not affected.
C. ... the outer loop is interrupted and the inner loop is not affected.
D. ... neither the inner loop, nor the outer loop are interrupted.
Ans: B
9. Given two variables, num1 and num2, which of the following would mean that both
num1 and num2 are positive integers?
A. (num1 = num2)
B. (num1 = num2) OR (num1 ≠ num2)
C. (num1 = num2) AND (num1<0)
D. (num1 = num2) AND (num2>0)
Ans: D
10. What will be the output of the following code?
x = 12
for i in x:
print(i)
A. 12
B. 1 2
C. Error
D. None of the above
Ans: C