Computer Science
Carefully go through the code given below and answer the questions based on it :
in1Str = input(" Enter string of digits: ")
in2Str = input(" Enter string of digits: ")
if len(in1Str)>len(in2Str):
small = in2Str
large = in1Str
else:
small = in1Str
large = in2Str
newStr = ''
for element in small:
result = int(element) + int(large[0])
newStr = newStr + str(result)
large = large[1:]
print (len(newStr)) # Line 1
print (newStr) # Line 2
print (large) # Line 3
print (small) # Line 4
Given a first input of 123 and a second input of 4567, what result is produced by Line 3?
- 3
- 7
- 12
- 45
- None of these
Python String Manipulation
3 Likes
Answer
Option 2 — 7
Explanation
For loop executes 3 times as length of smaller input is 3. Initial value of large is 4567.
1st Iteration
large = large[1:]
⇒ large = 567
2nd Iteration large = large[1:]
⇒ large = 67
3rd Iteration large = large[1:]
⇒ large = 7
Answered By
2 Likes
Related Questions
Carefully go through the code given below and answer the questions based on it :
in1Str = input(" Enter string of digits: ") in2Str = input(" Enter string of digits: ") if len(in1Str)>len(in2Str): small = in2Str large = in1Str else: small = in1Str large = in2Str newStr = '' for element in small: result = int(element) + int(large[0]) newStr = newStr + str(result) large = large[1:] print (len(newStr)) # Line 1 print (newStr) # Line 2 print (large) # Line 3 print (small) # Line 4
Given a first input of 12345 and a second input of 246, what result is produced by Line 1?
- 1
- 3
- 5
- 0
- None of these
Carefully go through the code given below and answer the questions based on it :
in1Str = input(" Enter string of digits: ") in2Str = input(" Enter string of digits: ") if len(in1Str)>len(in2Str): small = in2Str large = in1Str else: small = in1Str large = in2Str newStr = '' for element in small: result = int(element) + int(large[0]) newStr = newStr + str(result) large = large[1:] print (len(newStr)) # Line 1 print (newStr) # Line 2 print (large) # Line 3 print (small) # Line 4
Given a first input of 12345 and a second input of 246, what result is produced by Line 2?
- 369
- 246
- 234
- 345
- None of these
Carefully go through the code given below and answer the questions based on it :
in1Str = input(" Enter string of digits: ") in2Str = input(" Enter string of digits: ") if len(in1Str)>len(in2Str): small = in2Str large = in1Str else: small = in1Str large = in2Str newStr = '' for element in small: result = int(element) + int(large[0]) newStr = newStr + str(result) large = large[1:] print (len(newStr)) # Line 1 print (newStr) # Line 2 print (large) # Line 3 print (small) # Line 4
Given a first input of 123 and a second input of 4567, what result is produced by Line 4?
- 123
- 4567
- 7
- 3
- None of these
Find the output if the input string is 'Test'.
S = input("Enter String :") RS = " " for ch in S : RS = ch + RS print(S + RS)