Ad Code

Python Quiz 4 Answers 100% correct No UFM

 Programmer for Noobs

PYTHON Quiz 4 Answers




Q1.   How do you declare a dictionary in python ?


 (a): dict = {“key”:”value”}

(b): dict [“key”:”value”]

(c): Dict = {“key” – “value”}

(d): Dict = [“key”:”value”]

Reason: In Python, a Dictionary can be created by placing sequence of elements within curly {} braces, separated by 'comma'. Dictionary holds a pair of values, one being the Key and the other corresponding pair element being its Key:value . the answer is 

dict = {“key”:”value”}

Programmer for Noobs




Programmer for Noobs

Q2. What will be the output of the following code dict = { x:x for x in range(1,2) } print(dict)

1.{} 

2.{x:x,x:x,x:x} 

3.{1: 1, 2: 2} 

4.{1: 1}

Reason: It will be ranged between {1:1} because it has no other element to printed as well as we have executed the program also as per the lectures.

Programmer for Noobs





Programmer for Noobs

Q3. In python 3.x, Which of the following statement is true for following code: age = input (“Please enter your age”) 

1.Age will be integer type.

 2.It removes trailing spaces. 

3.age variable's type will be Whatever type is given to it 

4.None of the above

Reason:  In python 3.x is true for following code: age = input (“Please enter your age”) , so it is age variable's type  and the answer is none of the above . 

Programmer for Noobs





Programmer for Noobs

Q:4. What will be the output of the following program ?
        int =5
        while int <=-1:
            print (int)
            int = int -1

1.3
     2

2.blank (nothing will be printed)

3.5
     4
     3

4.5
     4
     3
     2
     1

Reason: If we execute the code then it will give nothing in the output window or we can say its blank

Programmer for Noobs

Programmer for Noobs

Q5. What will be the output of the following program ?
        int =3
        while int >=2:
            print (int)
            int = 1

1.3

2.2

3.3 2

4.Error in code

Reason: If we run this program it will only return 3 in the output, so 3 is the correct answer.

Programmer for Noobs 

Please subscribe to our channel 




Post a Comment

0 Comments