What will be the output of the following code?
a) A=’8’
print(A*5+str(int(A)*2)) 7.
Predict output of the following code:
A=[12,45,78,45,234]
B=len(A)
for i in range(0,B,2):
print(i)
Share
What will be the output of the following code?
a) A=’8’
print(A*5+str(int(A)*2)) 7.
Predict output of the following code:
A=[12,45,78,45,234]
B=len(A)
for i in range(0,B,2):
print(i)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Answer:
b) 0,2,4
len(A)= 5
(0,5,2)
0,2,4
(a) A = '8'
print(A*5+str(int(A)*2))
Output
8888816
(b) A = [12,45,78,45,234]
B = len(A)
for i in range(0, B, 2):
print(i)
Output
0
2
4
Let's correct the question
What will be the output of the following code?
(a) A='8'
print(A*5+str(int(A)*2))
(b) A=[12,45,78,45,234]
B=len(A)
for i in range(0,B,2):
print(i)
Explanation
(a) In this variable A is assigned with a string which is 8. In print() let's see step by step
A*5 => This is used to print the string which is present in A 5 times.
str(int(A)*2) => This is used to convert string to int. So, string 8 converts to int which means integer value and it is multiplied by 2 so, it comes out to be 16.
plus(+) operator is used to join results of both and that is how output comes out to be 8888816
(b) In this variable A is assigned with a list. Variable B stores the length of list A which tells how many items are present in list A.
for loop starts with 0 and runs till the end of the length of the list A which is 6 and it skips 2 values to print the value of i after each loop.
Extra Information
range() function is used to return a sequence of numbers in the order that we have set in the function.
Syntax of range() function
range(start, stop, step)
start is where we mention from which position the loop has to start. If not mentioned it starts from 0 by which we can say it is optional to mention it.
stop is where we want our loop to end. It is required to be mentioned.
step is used to increment so, that loop goes on. If not mentioned it has a default value of 1 by which we can say it is optional to mention it.
Python was created by Guido van Rossum and came into existence in 1991. It is a high-level and general programming language. It is a very lucid programming language as it has a good language construct and object-oriented approach. It is dynamically typed and garbage-collected.