0% found this document useful (0 votes)
167 views7 pages

Module 3

Uploaded by

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

Module 3

Uploaded by

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

IBM PY0101EN

Help
Python Basics for Data Science

Course Progress Dates Discussion

Course / Module 3 - Python Programming … / Graded Quiz: Python Programming…

You are taking "Final Exam" as a timed exam. Show more 00:47:06

Previous Next

Graded Quiz: Python Programming Fundamentals


Bookmark this page

Graded Quiz due Jun 9, 2024 15:35 IST Completed


Question 1
1.0/1.0 point (graded)
What is the output of the following code?

x = "Gone"
if x == "Go":
print('Go')
else:
print('Stop')
print('Mike')

Stop Mike

Go Mike

Mike

Go Stop


Answer
Correct: Correct! The if clause executes first, followed by the last print statement.

Submit You have used 2 of 2 attempts

Question 2
1.0/1.0 point (graded)
Which of the following is the value of x after the following lines of code?

x=1
x = x>5

False
1

True


Answer
Correct: The condition is false as the value of x is less than 5.

Submit You have used 1 of 2 attempts

Question 3
1.0/1.0 point (graded)
What is the output of the following few lines of code?

x = 5
while x != 2:
print(x)
x = x - 1

The program will never leave the loop


Answer
Correct: The loop breaks when x equals 2.

Submit You have used 1 of 2 attempts

Question 4
1.0/1.0 point (graded)
What is the result of running the following lines of code?

class Points(object):
def __init__(self, x, y):
self.x = x
self.y = y
def print_point(self):
print('x=', self.x, ' y=', self.y)

p1 = Points("A", "B")
p1.print_point()

x=y=

y=B

x=A y=B

x=A


Answer
Correct: The print statement will display the two values as 'x=1 y=2.

Submit You have used 1 of 2 attempts

Question 5
1.0/1.0 point (graded)
What is the output of the following few lines of code?

for i, x in enumerate(['A', 'B', 'C']):


print(i, 2 * x)

1 AA

2 BB

3 CC

0A

1B

2C

0A

2B

4C

0 AA

1 BB

2 CC


Answer
Correct:
The enumerate function adds a counter to an iterable, allowing you to loop through both the elements and their corresponding indices.

Submit You have used 2 of 2 attempts


Submit You have used 2 of 2 attempts

Question 6
0.0/1.0 point (graded)
What is the result of running the following lines of code?

class Points(object):
def __init__(self, x, y):
self.x = x
self.y = y
def print_point(self):
print('x=', self.x, ' y=', self.y)

p2 = Points(1, 2)
p2.x = 'A'
p2.print_point()

x=A y=A

x= A y=2

x=A, y=B

x= 1 y=2


Answer
Incorrect: Refer to the Functions video.

Submit You have used 2 of 2 attempts

Question 7
1.0/1.0 point (graded)
Considering the function delta, when will the following function return a value of 1?

def delta(x):
if x == 0:
y = 1
else:
y = 0
return y

When the input is 0

When the input is 1

Never

When the input is anything but 0


Answer
Correct: Correct! The function returns value 1 when the input is 0.

Submit You have used 2 of 2 attempts

Question 8
1.0/1.0 point (graded)
1.0/1.0 point (graded)
What is the output of the following lines of code?

a = 1
def do(x):
a = 100
return x + a

print(do(1))

101

102


Answer
Correct: The value of a=100 exists in the local scope of the function disregarding the value of a=1 in the global scope.

Submit You have used 1 of 2 attempts

Question 9
1.0/1.0 point (graded)
Which two of the following functions will perform the addition of two numbers with a minimum number of variables? [Select two]

def add(a, b):

return(a + b)

def add(a, b):

c = a+b

return(c)

def add(a, b):

return(sum(a, b))

def add(a, b):

return(sum((a, b)))


Answer
Correct:
Partially correct! It is one of the correct options.
Partially correct! It is one of the correct options.

Submit

Question 10
1.0/1.0 point (graded)
Why is it the best practice to have multiple except statements with each type of error labeled correctly?
It is not necessary to label errors

To determine the type of error thrown and its location within the program

To skip specific sections of code during its execution

Ensure catching the error for program termination


Answer
Correct: Multiple except statements will help in identifying each type of error.

Submit You have used 2 of 2 attempts

Previous Next

All Rights Reserved


edX
About
Affiliates
edX for Business
Open edX
Careers
News

Legal
Terms of Service & Honor Code
Privacy Policy
Accessibility Policy
Trademark Policy
Sitemap
Cookie Policy
Your Privacy Choices

Connect
Idea Hub
Contact Us
Help Center
Security
Media Kit

© 2024 edX LLC. All rights reserved.


深圳市恒宇博科技有限公司 粤ICP备17044299号-2

You might also like