100% found this document useful (3 votes)
6K views

Python Quizzes

Uploaded by

Sai Sai Nath
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
6K views

Python Quizzes

Uploaded by

Sai Sai Nath
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

 Dashboard / My courses / Python / Introduction to Python / Pre Quiz - Introduction to Python

Quiz review
Started on Thursday, 25 January 2024, 5:00 PM
State Finished
Completed on Thursday, 25 January 2024, 5:03 PM
Time taken 2 mins 22 secs
Marks 5/5
Grade 100 out of 100
Feedback Congratulations!!! You have passed by securing more than 80%

Question 1
Correct

Mark 1 out of 1

45573
Identify which of the following is an interpreted language.

Select one:
Pascal

Python

C++

45573
Your answer is correct.
Pascal, C and C++ are all compiled languages. Python is an interpreted language.
The correct answer is: Python

Question 2
Correct

Mark 1 out of 1

Python syntax is case-sensitive. State true or false.

Select one:
True 
45573
False

Case sensitive means that x is different from X. The value John is different from the value john. Python syntax is case-sensitive.
The correct answer is 'True'.
Question 3
Correct

Mark 1 out of 1

Select the command to be used to run the python script file named t.py.

Select one:
execute python t.py

python t.py

run python t.py

go python t.py

Your answer is correct.


To run python files in command prompt, set the path of python and run the file as python filename.py

45573
The correct answer is: python t.py

Question 4
Correct

Mark 1 out of 1

Select the method that can be used to create a directory.

Select one:
os.creat_dir()

os.create_dir()
45573
os.mkdir()

os.make_dir()

Your answer is correct.


Python’s OS module provides a method to create a directory i.e. os.mkdir(path). It creates a directory with the given path.
The correct answer is: os.mkdir()

45573
Question 5
Correct

Mark 1 out of 1

Name the creator of python.

Select one:
James Gosling

Guido van Rossum

Bill Gates

Steve Jobs

Your answer is correct.


Guido van Rossum is the creator of Python. Python was conceived in the late 1980s, and its implementation was started in December
1989.

45573
The correct answer is: Guido van Rossum

◄ Python Course Introduction - Video

Jump to...

Introduction to Python and Datatypes - Video ►

45573

45573

 Dashboard / My courses / Python / Introduction to Python / Practice Session - Data Types

Quiz review
Started on Thursday, 25 January 2024, 5:04 PM
State Finished
Completed on Thursday, 25 January 2024, 5:05 PM
Time taken 1 min 45 secs
Marks 4.00/4.00
Grade 100.00 out of 100.00
Feedback
Congratulations!!! You have passed by securing more than 80%

45573
Question 1
Correct

Mark 2.00 out of 2.00

Write the code to display the Python version by importing sys module.

import sys 

print( sys.version  )

Question 2
Correct

Mark 2.00 out of 2.00


45573

How will you display the info on float datatype by importing sys module?

import sys 

print( sys.float_info  )

◄ Data Types - Presentation Deck New


45573
Jump to...

Introduction to Python - Code Demo ►



 Dashboard / My courses / Python / Introduction to Python / Post Quiz - Introduction to Python

Quiz review
Started on Thursday, 25 January 2024, 5:06 PM
State Finished
Completed on Thursday, 25 January 2024, 5:08 PM
Time taken 1 min 47 secs
Marks 5/5
Grade 100 out of 100
Feedback Congratulations!!! You have passed by securing more than 80%

Question 1
Correct

Mark 1 out of 1

45573
In Python, recall who detects the syntax error and when.

Select one:
compiler/at runtime

compiler/at compile time

interpreter/at runtime

interpreter/at compile time

Your answer is correct. 45573


The syntax of the Python programming language is the set of rules which defines how a program will be written. Syntax errors arise when the Python parser
is unable to understand a line of code. Syntax errors are reported by the interpreter at runtime.

The correct answer is: interpreter/at runtime

Question 2
Correct

Mark 1 out of 1

45573
Identify the symbol that a Python single line comment begins with.

Select one:
//

$$

#

/*

Your answer is correct.


Single-line comments must be created by beginning a line with the hash (#) character and they are automatically terminated by the end of that line.
The correct answer is: #
Question 3
Correct

Mark 1 out of 1

Identify the style that the python paragraph comment uses.

Select one:
''' comments '''

/* comments */

// comments //

# comments #

Your answer is correct.


For writing python paragraph comments, you may use triple quoted string. Add the triple quoted string at the beginning and end of the
comment.
45573
The correct answer is: ''' comments '''

Question 4
Correct

Mark 1 out of 1

Select the command to be used to start Python from the command prompt.

Select one:
45573
execute python

python

go python

run python

Your answer is correct.


The command python must be used to start Python from the command prompt.
The correct answer is: python
45573
Question 5
Correct

Mark 1 out of 1

Select the correct code.

A.
print("Programming is fun")
print("Python is fun")

B.
print("Programming is fun")
print("Python is fun")

C.
print("Programming is fun)
print("Python is fun")

D.

print("Programming is fun")
45573
print("Python is fun)

Select one:

B

45573
Your answer is correct.
Option A is wrongly intended.
Option C and D are wrongly quoted.
The correct answer is: B

◄ Stationary Shop

Jump to...

45573 Pre Quiz - Control Structures ►



 Dashboard / My courses / Python / Control Structures / Pre Quiz - Control Structures

Quiz review
Started on Thursday, 25 January 2024, 5:09 PM
State Finished
Completed on Thursday, 25 January 2024, 5:11 PM
Time taken 2 mins 16 secs
Marks 5/5
Grade 100 out of 100
Feedback Congratulations!!! You have passed by securing more than 80%

Question 1
Correct

Mark 1 out of 1

45573
Define what kind of language is python ?

Select one:
Compiled

Interpreted

Compiled and Interpreted

Outsourced

Your answer is correct.

45573
The terms interpreted or compiled is not a property of the language but a property of the implementation. There are multiple
implementations of Python language. The official one is byte code ‘interpreted’. So, it is called as an interpreted language.

The correct answer is: Interpreted

Question 2
Correct

Mark 1 out of 1

45573
Object Oriented Programming is possible in Python. State whether 'True' or 'False'.

Select one:
True

False

Your answer is correct.


OOP is a programming paradigm or style where you code you logic in terms of Classes and Objects and the functionality is implemented as interaction
between these objects. Python supports OOP. You can code your logic in python using OOP or Procedural or in Functional manner too.

The correct answer is: True


Question 3
Correct

Mark 1 out of 1

Identify the correct operator for power(x^y).

Select one:

pow(x,y)

x^y

x**y

x^^y

Your answer is correct.


The ** operator in Python is used to raise the number on the left of ** to the power of the exponent on the right of **.
Eg : 5 ** 3 ; 5 is being raised to the 3rd power.

The correct answer is: x**y

45573
Question 4
Correct

Mark 1 out of 1

Identify which one of these is floor division.

Select one:
//

/ 45573
/*

Your answer is correct.


In Python 3, normal division (/) returns the quotient with decimal while floor division (//) returns the quotient after removing the digits
after the decimal point.

The correct answer is: //

Question 5
Correct
45573
Mark 1 out of 1

Mathematical operations can be performed on a string. State whether 'True' or 'False'.

Select one:
True

False 

Mathematical operations cannot be performed on a string


The correct answer is 'False'.
◄ Post Quiz - Introduction to Python

Jump to...

Control Structures - Video ►

45573

45573

45573

 Dashboard / My courses / Python / Control Structures / Practice Session - Conditional Statements

Quiz review
Started on Friday, 26 January 2024, 10:43 PM
State Finished
Completed on Friday, 26 January 2024, 10:44 PM
Time taken 1 min 3 secs
Marks 2.00/2.00
Grade 100.00 out of 100.00

Question 1
Correct

Mark 1.00 out of 1.00

Fill in the Blanks


45573
(Note: Do not leave blank spaces between the operators and operands when writing an expression)

int a=25;

if a%5==0  :

print(a," is divisible by 5");

Question 2

45573
Correct

Mark 1.00 out of 1.00

Fill the necessary part of the given single line statement:

(Note: Do not leave blank spaces between the operators and operands when writing an expression)

no=10

print('Even Number' if no%2==0 else  "Odd Number")

◄ Conditional Statements - Presentation Deck New 45573


Jump to...

Iterative Statements - Presentation Deck New ►



 Satya Yaduva…

 Dashboard / My courses / Python / Control Structures / Practice Session - Looping Statements

Quiz: Practice Session - Looping Statements


XP : 9/ 10

Time limit: 4 mins

Grading method: Highest grade

Note: Highest grade of all attempts will be considered

Grade to pass: 80.00 out of 100.00

Summary of your previous attempts

Marks / Grade /
Attempt State 4.00 100.00 Review Feedback

1 Finished 3.00 75.00 Review


Submitted Friday, 26 January Oops!! You have scored below 80%... So kindly make
2024, 10:47 PM
necessary preparations and reattempt...

2 Finished 4.00 100.00 Review


Submitted Friday, 26 January Congratulations!!! You have passed by securing more than
2024, 10:49 PM
80%

Highest grade: 100.00 / 100.00.


Overall feedback
Congratulations!!! You have passed by securing more than 80%

Re-attempt quiz

◄ Iterative Statements - Presentation Deck New

Jump to...

BMI Calculator ►

 Dashboard / My courses / Python / Control Structures / Post Quiz - Control Structures

Quiz review
Started on Friday, 26 January 2024, 10:49 PM
State Finished
Completed on Friday, 26 January 2024, 10:51 PM
Time taken 1 min 55 secs
Marks 5/5
Grade 100 out of 100
Feedback Congratulations!!! You have passed by securing more than 80%

45573

45573

45573
Question 1
Correct

Mark 1 out of 1

Analyse and find which of the following loops correctly computes 1/2 + 2/3 + 3/4 + ... + 99/100.
A:
sum = 0
for i in range(1, 99):
sum += i / (i + 1)

print("Sum is", sum)

B:
sum = 0
for i in range(1, 100):
sum += i / (i + 1)
print("Sum is", sum)

C:
sum = 0
for i in range(1.0, 99.0):
45573
sum += i / (i + 1)
print("Sum is", sum)

D:
sum = 0
for i in range(1.0, 100.0):
sum += i / (i + 1)
print("Sum is", sum)

Select one:

ABCD
45573
B

CD

BCD

CDE

Your answer is correct.


Python range() doesn’t support the float type. Hence, option C and D are invalid.

45573
Option A is invalid because i takes values from 1 to 98 - last fraction in the sequence is 98/99, not 99/100. Option B is correct.

The correct answer is: B


Question 2
Correct

Mark 1 out of 1

Evaluate the given code and tell which single line of code can be used to replace this sample code?

nums = [1,2,3,4,5,6,7,8,9]

x=0
for n in nums:

x=x+n
print(x)

Select one:

print(sum(range(0,9)))

print(sum(range(1,9)))

print(sum(1 to 10))
45573
print(sum(range(1,10)))

Your answer is correct.


The code represents the logic for finding the sum of numbers from 1-9. In this case, range must be from 1-10. Hence, the right syntax is :
print(sum(range(1,10)))
The correct answer is: print(sum(range(1,10)))

Question 3
Correct
45573
Mark 1 out of 1

Select the choices that should not appear in the place of EXP - given : for k in EXP:

Select one:

a range of float

a dictionary

a string

a list
45573
a range of int

Your answer is correct.


A list in the place of EXP will take you through the list elements. A dictionary will take you through the key/value pairs. A string will take
you through its characters. A range of integers will take you through the integers within the range. But a range of float in the place of EXP
in for is illegal.

The correct answer is: a range of float


Question 4
Correct

Mark 1 out of 1

Which statement best describes the behavior of the following expression?


x != 0 and y % x != 0

Select one:

It contains a type error

It causes a run-time error if x is not 0

It executes successfully for all values of x

It contains a syntax error

It causes a run-time error if x is 0

Your answer is correct.

45573
The expression is valid and it executes successfully for all values of x.

The correct answer is: It executes successfully for all values of x

Question 5
Correct

Mark 1 out of 1

Analyse and predict the output for the following.


isCorrect = False

45573
print("Correct" if isCorrect else "Incorrect")

Select one:
Nothing

Correct Incorrect

Incorrect

Correct

Your answer is correct.


"Correct" will get printed only if isCorrect is True. Since isCorrect is False, our output is Incorrect.

45573
The correct answer is: Incorrect

◄ Window seat or not

Jump to...

Pre Quiz - Collection Frameworks ►



 Dashboard / My courses / Python / Collection Frameworks / Pre Quiz - Collection Frameworks

Quiz review
Started on Friday, 26 January 2024, 10:53 PM
State Finished
Completed on Friday, 26 January 2024, 10:55 PM
Time taken 2 mins 36 secs
Marks 5/5
Grade 100 out of 100
Feedback Congratulations!!! You have passed by securing more than 80%

Question 1
Correct

Mark 1 out of 1

45573
Predict the right output for the following code.

i=5
while True:
if i%9 == 0:
break
print(i)
i += 1

Select one:

5 6 7 8 9 10 11 12 13 14 15 ….

45573
56789

Error

5 6 7 8

Your answer is correct.


Here, i is assigned the value 5. Execution of while loop stops when i%9 evaluates to 0. That is, when i is 9. Until then, i is printed and incremented by 1.
Hence, 5 6 7 8.
The correct answer is: 5 6 7 8

45573
Question 2
Correct

Mark 1 out of 1

Predict the correct output for the following code.


x = "abcdef"
i = "a"
while i in x:
print('i', end = " ")

Select one:
i i i i i i …

no output

aaaaaa…

abcdef
45573
Your answer is correct.
Since a in abcdef (i.e, i in x) is always true, the character i will get printed infinite no of times in the same line, separated by white spaces since end = " ".
The correct answer is: i i i i i i …

45573

45573
Question 3
Correct

Mark 1 out of 1

Analyse and predict the value of b after the execution of this loop?
b=0

for a in range(0, 10, 2):

b += a + 1

Select one:
25

20

36

45

45573
Your answer is correct.
Here, a will take values from 0 to 10-1, stepping by 2. Hence, a takes values 0,2,4,6 an 8.

b+=a+1 is equivalent to b=b+a+1.

When a is 0, b=0+0+1=1

When a is 2, b=1+2+1=4

When a is 4, b=4+4+1=9

When a is 6, b=9+6+1=16

When a is 8, b=16+8+1=25

After loop execution, b is 25.


45573
The correct answer is: 25

Question 4
Correct

Mark 1 out of 1

Select the statement that you can use for iterating over a block of statements N times

45573
Select one:
while n=0; n=n+1; n<N:

for n in range(N):

for n=0, n=n+1, n<N:

for n=1 to N:

while n in xrange(N):

Your answer is correct.


"for n in range(N):" is the only correct syntax for iterating over a block of statements N times.

The correct answer is: for n in range(N):


Question 5
Correct

Mark 1 out of 1

Analyse and select the statements that correctly explain the output of the given sample code.

if(True):
print("A")
if(100):

print("B")
if(" "):
print("C")
if ([[]]):

print("D")

Select one:
The following values are always interpreted as false:
False, None, numeric zero of all types, and empty strings and empty containers.

45573
User-defined objects can customize their truth value by providing a __bool__() method.

In the context of Boolean operations, the following values are interpreted as true: 
True, numeric non-zero of all types, non-empty strings and containers containing empty containers.

Your answer is correct.


The correct answer is: In the context of Boolean operations, the following values are interpreted as true:
True, numeric non-zero of all types, non-empty strings and containers containing empty containers.

◄ Post Quiz - Control Structures 45573


Jump to...

Lists, Tuples and Dictionaries - Video ►

45573

 Dashboard / My courses / Python / Collection Frameworks / Practice Session - Lists

Quiz review
Started on Friday, 26 January 2024, 11:03 PM
State Finished
Completed on Friday, 26 January 2024, 11:05 PM
Time taken 2 mins 20 secs
Marks 5.00/5.00
Grade 100.00 out of 100.00
Feedback
Congratulations!!! You have passed by securing more than 80%

45573
Question 1
Correct

Mark 1.00 out of 1.00

Create a list L1 with the elements 1,2,3,4,5,6.

L1=[1,2,3,4,5,6] 

Question 2
Correct

Mark 1.00 out of 1.00


45573

Display the third element of the list L1 using negative indexing.

print( L1[-4]  )

Question 3
Correct

Mark 1.00 out of 1.00


45573

Given the list : L1=[1,2,3,4,5,6], how will you display from the third element to the end of the list without specifying the end index?

print( L1[2:]  )
Question 4
Correct

Mark 1.00 out of 1.00

Given the list : L1=[1,2,3,4,5,6], how will you display the third and forth element by specifying positive start and end index ?

print( L1[2:4]  )

Question 5
Correct

Mark 1.00 out of 1.00

45573
Given the list: L1=[1,2,3,4,5,6], fill up the code to create a new list L2 that contains only the even numbers from the list L1 using the
concept of list comprehension.

(Note: Do not leave blank spaces between the operators and operands when writing an expression)

L2=[element for element in L1 if element%2==0  ]

◄ List - Presentation Deck New

Jump to...

45573 Tuples and Set - Presentation Deck New ►

45573

 Dashboard / My courses / Python / Collection Frameworks / Practice Session - Tuples

Quiz review
Started on Friday, 26 January 2024, 11:06 PM
State Finished
Completed on Friday, 26 January 2024, 11:09 PM
Time taken 3 mins 10 secs
Marks 3.00/3.00
Grade 100.00 out of 100.00
Feedback
Congratulations!!! You have passed by securing more than 80%

45573
Question 1
Correct

Mark 1.00 out of 1.00

Create a tuple (with parenthesis), new_tuple with 5 elements – 101,102,103,104,105.

new_tuple=(101,102,103,104,105) 

Question 2

45573
Correct

Mark 1.00 out of 1.00

Given the tuple new_tuple = (101, 102, 103, 104,105), how will you display its third element ?

print( new_tuple[2]  )

Question 3
Correct

Mark 1.00 out of 1.00

45573
Fill up the code pertaining to enumerate method that adds index to the tuple, to bind index with the associated value using a for loop.

tup=(1,2,3,4,5)

for index,tup in enumerate(tup)  :

print(index, tup)

◄ Tuples and Set - Presentation Deck New

Jump to...

Dictionary - Presentation Deck New ►


45573

45573

45573

 Dashboard / My courses / Python / Collection Frameworks / Practice Session - Dictionaries

Quiz review
Started on Friday, 26 January 2024, 11:20 PM
State Finished
Completed on Friday, 26 January 2024, 11:22 PM
Time taken 1 min 49 secs
Marks 5.00/5.00
Grade 100.00 out of 100.00
Feedback
Congratulations!!! You have passed by securing more than 80%

45573
Question 1
Correct

Mark 3.00 out of 3.00

Create a dictionary – Student_detail with the following key-value pair. Key - Name and Value – Ram.

Note: use single quotes for representing the key and the value, do not leave spaces

Student_detail={'Name':'Ram'} 

Question 2
Correct
45573
Mark 2.00 out of 2.00

To the dictionary Student_detail, add a new key-value pair. Key - Languages_known and Value - English, Tamil, Hindi

Student_detail={'Name':'Ram'}

Note: use single quotes for representing the key and the values, do not leave spaces

45573
Student_detail['Languages_known']=['English','Tamil','Hindi'] 

◄ Dictionary - Presentation Deck New

Jump to...

Arrange Names ►

 Dashboard / My courses / Python / Collection Frameworks / Post Quiz - Collection Frameworks

Quiz review
Started on Friday, 26 January 2024, 11:26 PM
State Finished
Completed on Friday, 26 January 2024, 11:27 PM
Time taken 40 secs
Marks 5/5
Grade 100 out of 100
Feedback Congratulations!!! You have passed by securing more than 80%

Question 1
Correct

Mark 1 out of 1

45573
Analyse the code and predict the output.
myList = [1, 5, 5, 5, 5, 1]
max = myList[0]
indexOfMax = 0
for i in range(1, len(myList)):
if myList[i] > max:
max = myList[i]
indexOfMax = i
print(indexOfMax)

Select one: 45573


4

1

Your answer is correct.


The max is assigned with the first value in the list (value at 0th index). The for loop ranges from 1 to 6-1. For every iteration, the value of max is updated,

45573
when a value greater than max is encountered. Finally, the index of max is printed. The index of max value 5 is 1 because there had not been a value greater
than 5 after 5 had been encountered at the 1st index.
The correct answer is: 1
Question 2
Correct

Mark 1 out of 1

Evaluate the given code snippet. Ignoring the order, which line of code will you use in the place of "# LINE A" to generate the output
shown here ?

keys = ['key1', 'key2', 'key3', 'key4', 'key5']

vals = ['val1', 'val2', 'val3', 'val4', 'val5']

# LINE A
print(mydict)

# Output: {'key1': 'val1', 'key2': 'val2', 'key3': 'val3', 'key4': 'val4', 'key5': 'val5'}

Select one:

45573
mydict = dict() 
for x in range(len(keys)):
mydict[keys[x]] = vals[x]

mydict = dict()
mydict.fromkeys(keys, vals)

mydict = dict(keys.join(vals))

mydict = dict(keys, vals)

mydict = dict()
for x in keys:

45573
mydict[x] = vals.pop()

Your answer is correct.


We have a list of keys and a list of values. We must associate keys with values based on the list index. Create an empty dictionary. Iterate through this
dictionary, length of key_list no. of times. During each iteration, assign each key (from the key_list) with value at the equivalent index (in the value_list).
The correct answer is: mydict = dict()
for x in range(len(keys)):
mydict[keys[x]] = vals[x]

45573
Question 3
Correct

Mark 1 out of 1

Evaluate the given code. What is the value pertaining to (a == b, a is b) after the execution ?

a = [1, 2, 3, 1]
b = [1, 2, 3, 1]

Select one:
(False, False)

It causes a run-time error, because == can only be applied to primitive types.

(True, False)

(False, True)

(True, True)

45573
Your answer is correct.
The == operator compares values of both the operands (a and b) and checks for value equality. Hence, true.

The is operator checks whether both the operands refer to the same object or not. Hence, false.

The correct answer is: (True, False)

Question 4
Correct

Mark 1 out of 1
45573
Describe what will happen during the dictionary update dict[k] = v, if k isn’t present in dict.

Select one:

The program continues with dict unchanged

The entry (k, v) is added to the dictionary

45573
The program updates the key which is closest to k

The program stops with a run-time error

Your answer is correct.


When trying to assign a value(v) to the key(k) that's not present in the dict, a new key-value pair gets created.

The correct answer is: The entry (k, v) is added to the dictionary
Question 5
Correct

Mark 1 out of 1

Select the statement(s) that is/are true.

Select one or more:

Tuples are homogeneous, lists are heterogeneous

Tuples are structured, lists are ordered

Dictionaries are indexed, lists and tuples are key-value paired

Tuples are immutable, lists are mutable.

Your answer is correct.

45573
Tuples are immutable and structured.
Lists are mutable and ordered.

The correct answers are: Tuples are structured, lists are ordered, Tuples are immutable, lists are mutable.

◄ Residents' Information

Jump to...

Pre Quiz - Functions and Modules ►

45573

45573

 Dashboard / My courses / Python / Functions and Modules / Pre Quiz - Functions and Modules

Quiz review
Started on Friday, 26 January 2024, 11:36 PM
State Finished
Completed on Friday, 26 January 2024, 11:38 PM
Time taken 2 mins 2 secs
Marks 5/5
Grade 100 out of 100
Feedback Congratulations!!! You have passed by securing more than 80%

Question 1
Correct

Mark 1 out of 1

45573
If a=[20,30,40,50,60], show the value of a[3].

Select one:
50

60

None of these options

40

Your answer is correct.

45573
List index starts with 0. Hence, a[3] refers to the 4th element in the list which is 50.
The correct answer is: 50

45573
Question 2
Correct

Mark 1 out of 1

Consider the following code snippet:


1. list = [ [ ] ] * 5
2. list # output?
3. list[0].append(10)
4. list # output?
5. list[1].append(20)
6. list # output?
7. list.append(30)
8. list # output?

Analyse and select the outputs for the lines 2, 4, 6, and 8?

Select one:

[[], [], [], [], []] 

45573
[[10], [10], [10], [10], [10]]
[[10, 20], [10, 20], [10, 20], [10, 20], [10, 20]]
[[10, 20], [10, 20], [10, 20], [10, 20], [10, 20], 30]

[[], [], [], [], []]


[[10], [10], [10], [10], [10]]
[[10, 20], [10, 20], [10, 20], [10, 20], [10, 20]]
[[10, 20], [10, 20], [10, 20], [10, 20], [10, 20], [10,30]]

[[], [], [], [], []]


[[], [], [], [], [],[10]]
[[10, 20], [10, 20], [10, 20], [10, 20], [10, 20]]
[[10, 20], [10, 20], [10, 20], [10, 20], [10, 20], 30]

[[], [], [], [], []]


[[10], [10], [10], [10], [10]] 45573
[[10], [10], [10], [10], [10],[20]]
[[10, 20], [10, 20], [10, 20], [10, 20], [10, 20], [10,30]]

Your answer is correct.


list =[ [ ] ] * 5 creates a list containing 5 empty lists.
list[0].append(10) appends value 10 to the 0th index of every list within the list of lists.
list[1].append(20) appends value 20 to the 1st index of every list within the list of lists.
list.append(30) appends value 30 to the list of lists.

45573
The correct answer is: [[], [], [], [], []]
[[10], [10], [10], [10], [10]]
[[10, 20], [10, 20], [10, 20], [10, 20], [10, 20]]
[[10, 20], [10, 20], [10, 20], [10, 20], [10, 20], 30]
Question 3
Correct

Mark 1 out of 1

Analyse the following code and predict the output.

list1 = [2,4,6,8,10,12,14,16,18,20]

print (list1[0:1],list1[5:7])

Select one:
[2][12,14,16]

[4][14,16]

Error

[2] [12, 14]

Your answer is correct. 45573


[0:1] means the element at the 0th index and (1-1)th index, which is again 0th index.

[5:7] means the elements at 5th and 6th index .

The correct answer is: [2] [12, 14]

Question 4
Correct

Mark 1 out of 1

45573
Create a string with the numbers from 0 to 100, "0123456789101112...". Choose the correct statement.

Select one:

"".join([str(x) for x in range(101)])

"''.join([`x` for x in range(100)])

"''.append([`x` for x in xrange(101)])

"''.append([`x` for x in xrange(100)])

Your answer is correct.


45573
The method xrange is deprecated in Python3. Hence eliminate the choices with xrange.
A string with the numbers from 0 to 100 requires the range-end to be 101.

The method join returns a string in which the elements of sequence have been joined by a str separator.
The only statement relevant to our scenario is "''.join([`x` for x in range(101)])

The correct answer is: "".join([str(x) for x in range(101)])


Question 5
Correct

Mark 1 out of 1

"The 'break' statement can be used to terminate the 'if' condition". State True or False:

Select one:

True

False 

The 'break' statement is used to break out of a loop.


The correct answer is 'False'.

45573
◄ Post Quiz - Collection Frameworks

Jump to...

Functions - Video ►

45573

45573

 Dashboard / My courses / Python / Functions and Modules / Practice Session - Functions

Quiz review
Started on Sunday, 28 January 2024, 4:29 PM
State Finished
Completed on Sunday, 28 January 2024, 4:30 PM
Time taken 1 min 10 secs
Marks 6.00/6.00
Grade 100.00 out of 100.00
Feedback
Congratulations!!! You have passed by securing more than 80%

45573
Question 1
Correct

Mark 6.00 out of 6.00

Get integer inputs for var1 and var2 from the user.
Define a function ‘add’, that takes var1 and var2 as arguments and returns its sum (return without parenthesis).

Call the function. Capture the sum in var3 and print.

# variable declaration

var1=int(input()) 
var2=int(input())

# function definition

45573
def add(var1,var2): 
return var1+var2 

# function call and print result

var3=add(var1,var2) 
print(var3) 

◄ Functions - Presentation Deck New 45573


Jump to...

Modules and Packages - Presentation Deck New ►



 Dashboard / My courses / Python / Functions and Modules / Practice Session - Modules

Quiz review
Started on Sunday, 28 January 2024, 4:33 PM
State Finished
Completed on Sunday, 28 January 2024, 4:34 PM
Time taken 34 secs
Marks 1.00/1.00
Grade 100.00 out of 100.00
Feedback
Congratulations!!! You have passed by securing more than 80%

45573
Question 1
Correct

Mark 1.00 out of 1.00

Import sqrt function from math module. Print the square root of 25 using this function.

from math import sqrt 

print(sqrt(25)) 

45573
◄ Modules and Packages - Presentation Deck New

Jump to...

Numpy Package - Presentation Deck Ne ►

45573

 Dashboard / My courses / Python / Functions and Modules / Practice Session - Numpy package

Quiz review
Started on Sunday, 28 January 2024, 4:36 PM
State Finished
Completed on Sunday, 28 January 2024, 4:37 PM
Time taken 49 secs
Marks 1.00/1.00
Grade 100.00 out of 100.00
Feedback
Congratulations!!! You have passed by securing more than 80%

45573
Question 1
Correct

Mark 1.00 out of 1.00

Fill up the code to generate and print 15 random integers between 1 to 100.
import numpy as np

print(np.random.randint(1,100,15)) 

45573
◄ Numpy Package - Presentation Deck Ne

Jump to...

Lucky Number ►

45573

 Dashboard / My courses / Python / Functions and Modules / Post Quiz - Functions and Modules

Quiz review
Started on Sunday, 28 January 2024, 4:39 PM
State Finished
Completed on Sunday, 28 January 2024, 4:42 PM
Time taken 3 mins 42 secs
Marks 10/10
Grade 100 out of 100
Feedback Congratulations!!! You have passed by securing more than 80%

Question 1
Correct

Mark 1 out of 1

45573
Veena, a beginner in Python programing has written the code for counting the number of elements in the list. The code that she has
written is given below. Analyse and display the output for the given code.

def addItem(listParam):
listParam += [1]

mylist = [1, 2, 3, 4]
addItem(mylist)
print len(mylist)

Select one:

4
45573
5

Your answer is correct.


The list - mylist has 4 elements in it. On calling addItem() once, element 1 is added to this list. Length of mylist is 5 after the function execution.

The correct answer is: 5

45573
Question 2
Correct

Mark 1 out of 1

Analyze the code given below and choose the correct output.

d = lambda p: p * 2
t = lambda p: p * 3
x=2
x = d(x)
x = t(x)
x = d(x)
print(x)

Select one:
12

36

48

24
45573
Your answer is correct.
After assigning x with 2, d(x) is the first call to lambda function. The function returns 4(2*2) and is assigned to x.

t(x) is the second call and the function returns 12(4*3) and is assigned to x.

d(x) is the third call and the function returns 24(12*2) and is assigned to x. Now, x is 24.

The correct answer is: 24

45573
Question 3
Correct

Mark 1 out of 1

Identify which of the following methods return a string that represents the present working directory.

Select one:

os.pwd()

os.cwd() 45573
os.getcwd()

os.getpwd()

Your answer is correct.


The function getcwd() (get current working directory) returns a string that represents the present working directory.

The correct answer is: os.getcwd()


Question 4
Correct

Mark 1 out of 1

Describe the process of pickling in Python.

Select one:
conversion of a byte stream into Python object hierarchy

conversion of a list into a data table

conversion of a data table into a list

conversion of a Python object hierarchy into byte stream

Your answer is correct.


Pickling is the process of serializing and de-serializing Python object structures. Serialization is the process of converting an object in memory into a byte

45573
stream which can be stored on disk or sent over network.

The correct answer is: conversion of a Python object hierarchy into byte stream

Question 5
Correct

Mark 1 out of 1

Choose the best statement that describes the output of the given code snippets:
numbers=[-2,4,6,-1]
new_no = list(filter(lambda x:x>0,numbers ))

Select one:
45573
It will filter the negative numbers from a list

It will throw an error

It will filter the positive numbers from a list

It will filter all the numeric values from the list

Your answer is correct.

The correct answer is: It will filter the positive numbers from a list

45573
Question 6
Correct

Mark 1 out of 1

Identify which of the following functions can be used to create a symbolic link.

Select one:

os.symb_link()

os.symlink()

os.ln()

os.symblin()

Your answer is correct.


The method os.symlink() creates a symbolic link which contains a text string that is automatically interpreted and followed by the os as

45573
a path to another file or directory.
The correct answer is: os.symlink()

Question 7
Correct

Mark 1 out of 1

Which of the following functions can be used to read data from a file using a file descriptor?

Select one:

os.scan()

os.reader()
45573
os.quick_read()

os.read()

Your answer is correct.


The method read() reads at most n bytes from the file descriptor and will return a string containing all the bytes read.
The correct answer is: os.read()

45573
Question 8
Correct

Mark 1 out of 1

Describe what os.name contains.

Select one:

the address of the module os

error, it should’ve been os.name()

the name of the operating system dependent module imported

Your answer is correct.


You can get the name of the current running Operating System by checking : os.name.
The correct answer is: the name of the operating system dependent module imported

Question 9
Correct

Mark 1 out of 1
45573
State what print(os.geteuid()) prints?

Select one:

the user id of the current process

both the group id and the user of the current process

the group id of the current process


45573
Your answer is correct.
The method os.geteuid() gives the user id of the current process while the method os.getegid() gives the group id of the current process.
The correct answer is: the user id of the current process

Question 10
Correct

Mark 1 out of 1

State what os.close(f) does? 45573


Select one:

Terminates the process f

Returns an integer telling how close the file pointer is to the end of file

Tterminates the process f if f is not responding

Closes the file descriptor f

Your answer is correct.


When a file descriptor is passed as an argument to os.close() method, it is closed.

The correct answer is: Closes the file descriptor f


◄ Weather Analysis - Numpy array

Jump to...

Pre Quiz -File Handling ►

45573

45573

45573

 Dashboard / My courses / Python / File Handling / Pre Quiz -File Handling

Quiz review
Started on Sunday, 28 January 2024, 6:18 PM
State Finished
Completed on Sunday, 28 January 2024, 6:19 PM
Time taken 57 secs
Marks 5/5
Grade 100 out of 100
Feedback Congratulations!!! You have passed by securing more than 80%

Question 1
Correct

Mark 1 out of 1

45573
Which of the following is a contiguous set of bytes used to store data in a specific organized format?

Select one:
A folder

A file

A command line argument

A file system

Your answer is correct.


45573
The correct answer is: A file

Question 2
Correct

Mark 1 out of 1

"Byte files are then translated into binary 1 and 0 for easier processing by the computer."

45573
State whether true or false.

Select one:
True

False

Your answer is correct.

The correct answer is: True


Question 3
Correct

Mark 1 out of 1

Choose the main parts of files on most modern file systems :

Select one or more:


End of file (EOF): special character that indicates the end of the file

Header: metadata about the contents of the file (file name, size, type, and so on)

Properties: name,size,creation date, modification date and contents of the file as written by the creator or editor

Data: contents of the file as written by the creator or editor

Your answer is correct.

45573
The correct answers are: Header: metadata about the contents of the file (file name, size, type, and so on), Data: contents of the file as written by the creator
or editor, End of file (EOF): special character that indicates the end of the file

Question 4
Correct

Mark 1 out of 1

The file path is a string that represents the location of a file. What are major parts of a file path?

Select one or more:

45573
File System: identifies which file system structure it is used.

Extension: the end of the file path pre-pended with a period (.) used to indicate the file type

File Name: the actual name of the file

Folder Path: the file folder location on the file system where subsequent folders are separated by a forward slash / (Unix) or 
backslash \ (Windows)

Your answer is correct.

The correct answers are: Folder Path: the file folder location on the file system where subsequent folders are separated by a forward slash / (Unix) or
backslash \ (Windows), File Name: the actual name of the file, Extension: the end of the file path pre-pended with a period (.) used to indicate the file type

45573
Question 5
Correct

Mark 1 out of 1

An encoding is a translation from byte data to human readable characters. What are the most common character encodings formats?

Select one or more:


Unicode (UTF-8)

Object Code

Byte Code

ASCII

Your answer is correct.

The correct answers are: ASCII, Unicode (UTF-8)

45573
◄ Post Quiz - Functions and Modules

Jump to...

Working with Files - Video ►

45573

45573

 Dashboard / My courses / Python / File Handling / Practise Session - Files

Quiz review
Started on Sunday, 28 January 2024, 12:52 AM
State Finished
Completed on Sunday, 28 January 2024, 12:55 AM
Time taken 2 mins 38 secs
Marks 3.00/3.00
Grade 100.00 out of 100.00
Feedback
Congratulations!!! You have passed by securing more than 80%

45573
Question 1
Correct

Mark 1.00 out of 1.00

Open the file ‘odi.csv’ using DictReader in read mode and store it in the variable reader. (Use single quotes and do not leave the blank
spaces)

reader=csv.DictReader(open('odi.csv','r')) 

Question 2
Correct
45573
Mark 2.00 out of 2.00

Fill the code to open the text file data_science in read mode using with statement and to print all the statements within the file. (Use
single quotes and do not leave the blank spaces)

with open('data_science.txt','r')  as f:

print(f. readlines()  )

45573
◄ JSON and XML Files - Presentation Deck New

Jump to...

Store Student Data ►



 Dashboard / My courses / Python / File Handling / Post Quiz - File Handling

Quiz review
Started on Sunday, 28 January 2024, 12:44 AM
State Finished
Completed on Sunday, 28 January 2024, 12:47 AM
Time taken 3 mins 23 secs
Marks 5/5
Grade 100 out of 100
Feedback Congratulations!!! You have passed by securing more than 80%

Question 1
Correct

Mark 1 out of 1

45573
Select the correct built-in function(s) to read a line of text from standard input, which by default comes from the keyboard.

Select one:
scanner

scanner

input

output

Your answer is correct.

45573
The input() function reads a line entered on a console by an input device such as a keyboard and convert it into a string and returns it
The correct answer is: input

Question 2
Correct

Mark 1 out of 1

"You can read all the lines in the text file using .readlines() function". State True or False.

Select one:

45573
True 

False

The method readlines() returns a list containing all the lines from the file.
The correct answer is 'True'.
Question 3
Correct

Mark 1 out of 1

"We can open a file in “a” mode to append text towards the end of the file". State True or False.

Select one:

True 

False

We can open file in “a” mode to append text towards the end of the file. The file pointer is at the end of the file if the file exists. If the file
does not exist, it creates a new file for writing.
The correct answer is 'True'.

Question 4
Correct

Mark 1 out of 1
45573
Select the correct option(s) that describe(s) "pickling" in Python.

Select one:
It is for garbage collection

It is used for object serialization

It is used for object de-serialization

Your answer is correct.


45573
Python pickle module is used for serializing and de-serializing a Python object structure.
Any object in Python can be pickled so that it can be saved on disk. Pickle “serializes” the object first, before writing it to file.
Pickling is a way to convert a python object (list, dict, etc.) into a character stream.
The correct answer is: It is used for object serialization

Question 5
Correct

Mark 1 out of 1

45573
"When we use DictReader for reading small csv files, each line in the file is read as dictionary and columns in the data will be available as
keys of the dictionary". State True or False.

Select one:

True 

False

DictReader reads each line of a csv file as a dictionary and every column becomes the key of the dictionary.
The correct answer is 'True'.

◄ Filter Customers - JSON File


Jump to...

Find Sum - Code Analysis ►

45573

45573

45573

You might also like