0% found this document useful (0 votes)
2 views8 pages

Weekly Quiz - Introduction To Python

The document contains a series of questions and answers related to Python programming concepts, including list indexing, data types, typecasting, loops, and error handling. Each question is followed by the correct answer and explanations for the concepts involved. The document serves as a quiz or educational material for learning Python basics.

Uploaded by

priyasaki001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

Weekly Quiz - Introduction To Python

The document contains a series of questions and answers related to Python programming concepts, including list indexing, data types, typecasting, loops, and error handling. Each question is followed by the correct answer and explanations for the concepts involved. The document serves as a quiz or educational material for learning Python basics.

Uploaded by

priyasaki001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Q No: 1

Correct Answer
Marks: 1/1
The indexing in Python's 'list' data structure starts from 0.

True
You Selected
False
Each item in a list corresponds to an index number, which is an integer value, starting with the index
number 0.
Each item in a list corresponds to an index number, which is an integer value, starting with the index
number 0.
Q No: 2

Correct Answer
Marks: 1/1
b = 3.1

What is the data type of b?

int

str

float
You Selected
bool

Data type of b is float.

b=3.1

type(b)

Output: float

The data type of b is float.

b=3.1
type(b)

Output: float

Q No: 3

Correct Answer
Marks: 1/1
list_1 = ['a','b','c','d']

Which of the following codes give the output 'c'?

a) list_1[-2]
b) list_1[2]
c) list_1[3]
d) list_1[-1]

c and d

a and b
You Selected
All of the Mentioned

b and d

list_1 = ['a','b','c','d']

list_1[2]

Output: 'c'

list_1[-2]:

Output: 'c'

list_1 = ['a','b','c','d']
list_1[2]

The number within [ ] indicates the index of the element in that position.

For the above list - the elements and their corresponding index values are,

Element Index value (From start ) a 0 b 1 c 2 d 3

Thus, for the list_1[2], we get the output,

Output: 'c'

list_1 = ['a','b','c','d']
list_1[-2]

Similarly, the number with a negative sign indicates the index but from backwards.
For the above list - the elements and their corresponding index values are from backwards are,

Element Index values (backwards) a -4 b -3 c -2 d -1

Thus, by writing list_1[-2], the output is -


Output: 'c'

Q No: 4

Correct Answer
Marks: 1/1
Changing one particular data type to another is called typecasting.

True
You Selected
False
Typecasting in Python is a process of changing one data type into another. A lot of the time, while
dealing with certain operations, we need to change the data type to achieve successful results.
Typecasting in Python is a process of changing one data type into another. A lot of the time, while
dealing with certain operations, we need to change the data type to achieve successful results.
Q No: 5

Correct Answer
Marks: 1/1

What will be the value of the variable 'a' after the fourth iteration of the following for loop?

a= 1
for i in range(1,6):
a = a* i
print(a)

24
You Selected
720

a= 1

for i in range(1,6):
a = a* i
print(a)

Output:
1
2
6
24
120

a= 1
for i in range(1,6):
a = a* i
print(a)

Output:

In the 1st iteration, i =1 and a =1, so the output will be a*i=1*1=1

In the 2nd iteration, i =2 and a =1 (from the previous output), so the output will be a*i=1*2=2

In the 3rd iteration, i = 3 and a =2 (from the previous output), so the output will be a*i=2*3=6

In the 4th iteration, i = 4 and a =6 (from the previous output), so the output will be a*i=6*4=24 and so
on.

Hence the answer is: 24

If we print the code, the output will be-

24

120

Q No: 6

Correct Answer
Marks: 1/1

What will be the output of the following code snippet (in Python 3)?

i='20'
if i>20:
print(1)
else:
print(2)
1

Error
You Selected
20
i='20'
if i>20:
print(1)
else:
print(2)
Output:
TypeError: '>' not supported between instances of 'str' and 'int'
type(i)
output:
str

i='20'
if i>20:
print(1)
else:
print(2)
Output:
TypeError: '>' not supported between instances of 'str' and 'int'
The is because we have assigned the value 20 within single inverted commas, { i= '20' } and in
python, any value within ' ' this is interpreted as a string. To check, you can run the following,
type(i)

The output will be: str


Since '>' can compare only two objects of the same data type, it fails to compare a string object with
an integer and hence raises that type error.
Q No: 7

Correct Answer
Marks: 1/1

Consider the following mathematical expression where x,y and z are three different numbers-

(x**y) + (y/z) + (x-y) +(z-y) - (y*x)

For what combination of x,y, and z we get the answer to be 15593.0

x = 5, y = 6, z = 3
You Selected
x = 0.99, y = 100, z = 9
x = 20, y = 3, z = 22

x = 15, y = 2, z = 19

x=5
y=6
z=3

(x**y) + (y/z) + (x-y) +(z-y) - (y*x)

OUTPUT:

15593.0

To understand which combination is appropriate, use the following code-

x = 5
y = 6
z = 3
(x**y) + (y/z) + (x-y) +(z-y) - (y*x)

OUTPUT:

15593.0

Q No: 8

Correct Answer
Marks: 1/1

What is the output of the following code snippet?

print('\')

'\'

/
Error
You Selected

print('\')

Output:

SyntaxError: EOL while scanning string literal

To know the appropriate output,just run the given code -

print('\')

Output:

SyntaxError: EOL while scanning string literal

Q No: 9

Correct Answer
Marks: 1/1

The following data structure is a dictionary.

c= {
"fruit:", "Apple",
"vegetable:", "Tomato",
"flower:", "Rose"
}

True

False
You Selected

c= {
"fruit:", "Apple",
"vegetable:", "Tomato",
"flower:", "Rose"
}

type(c)

Output:

set
c= {"fruit:", "Apple","vegetable:", "Tomato","flower:","Rose"}
type(c)

Output:

set

Here, c is of the form -

c = { 'element 1' , 'element 2' , ..., 'element 100'}

To be a dictionary, it should be like,

c = { key:value , key:value,...., key:value}

that is,

c = { 'fruit' : ' Apple', 'vegetable' : 'Tomato', 'flower' : 'Rose' }

Hence the answer follows.

Q No: 10

Correct Answer
Marks: 1/1
We can write latex commands using dollar signs in the markdown cells of Jupyter Notebook.

True
You Selected
False
Yes, We can use latex commands in-line with dollar signs in the markdown cells.
Yes, We can use latex commands in line with dollar signs in the markdown cells.
Comments:

You might also like