WELCOME GUYS TO MY BLOG
Q:1. How do you declare a dictionary in python ?
ANSWER 2.dict = {“key”:”value”}
REASON
Dictionary id listed in curly brackets inside these curly brackets, key and value are declared, each key is separated from its value by a colon (:), while commas separate each element.
Q:2. What will be the output of the following code:
dict = { x:x for x in range(1,2) }
print(dict)
ANSWER 4.{1: 1}
REASON
As the for loop runs upto one hence {1:1} will print.
Q:3. In python 3.x, Which of the following statement is true for following code:
age = input (“Please enter your age”)
ANSWER 4.None of the above
REASON
We are asking for the age in the age = input("Please enter your age"), hence none of the above statement is true hence answer is none of the above.
Q:4. What will be the output of the following program ?
int =5
while int <=-1:
print (int)
int = int -1
ANSWER 2.blank(nothing will be printed)
REASON
As in the program while condition is not true hence it will not run, and out side the while loop nothing is printed therefore second option is correct.
Q:5. What will be the output of the following program ?
int =3
while int >=2:
print (int)
int = 1
ANSWER 1,3
REASON
while condition is satisfied hence it will print 3 as it declared above. But in end int = 1 it will not print as print statement is not written.
Comments
Post a Comment