X
([Link] ([Link]
prashanth049@[Link]
NPTEL ([Link] » Programming with Generative AI (course)
Course Week 3 Assignment 3
outline The due date for submitting this assignment has passed.
Due on 2025-09-10, 23:59 IST.
Week 1 ()
How does an
Assignment submitted on 2025-09-10, 23:17 IST
NPTEL 1) Consider the following Python function: 1 point
online
course def f(x, y, z):
work? () return (x + y) == z
Week 1 Part Select all expressions that evaluate to True from the options below.
1
Introduction f(0, 0, 0.0)
()
f(1 / 2, 1 / 2, 1)
Week 1 Part f(1 // 2, 1 // 2, 1)
2 Getting f('', '', '')
started with f(0.1, 2 * 0.1, 0.3)
Python ()
Yes, the answer is correct.
Score: 1
Week 2 Part
Accepted Answers:
1 Variables
f(0, 0, 0.0)
and
f(1 / 2, 1 / 2, 1)
Assignments
f('', '', '')
()
2) Your friend has written the following function based on this 1 point
Week 2 Part
2 Functions ([Link] Wikipedia article:
and Simple
Programs () def f(x: float) -> float:
return x / 4.184
The names f and x are meaningless. Which of the following are the most appropriate names for
Week 3 Part
this function and parameter from the options below?
1 User-
defined
The function name should be to_calories
functions ()
The function name should be to_joules
Week 3 Part The function name should be to_kilojoules
2 Refuting The parameter name should be calories
and
The parameter name should be joules
debugging
complex The parameter name should be kilojoules
functions ()
Yes, the answer is correct.
Score: 1
Example 1
Accepted Answers:
(is_multiple)
The function name should be to_calories
(unit?
The parameter name should be joules
unit=95&lesso
n=108)
3) Your friend has written the following function based on this 1 point
Visualizing ([Link] Wikipedia article:
Example 1
(unit? def f(x: int, y: int) -> float:
unit=95&lesso return x / y ** 2 * 703
n=109)
Visualizing a Which of the following are helpful suggestions to give to your friend?
function call
(unit?
The expression x / y ** 2 * 703 should be rewritten as (x / (y ** 2)) *
unit=95&lesso 703
n=110) The function name should be BMI
The error in The function name should be bodyMassIndex
Example 1
The function name should be body_mass_index
(unit?
unit=95&lesso The parameter x should be renamed mass_kg
n=111) The parameter x should be renamed mass_lb
Fixing the The parameter y should be renamed height_m
code (unit? The parameter y should be renamed height_in
unit=95&lesso
n=112) No, the answer is incorrect.
Score: 0
Key Accepted Answers:
Observations The expression x / y ** 2 * 703 should be rewritten as (x / (y ** 2)) * 703
(unit?
The function name should be body_mass_index
unit=95&lesso
The parameter x should be renamed mass_lb
n=113)
The parameter y should be renamed height_in
Example 2
(modified
4) Consider the following Python function: 1 point
is_multiple)
(unit?
def f(x: int, y: int) -> int:
unit=95&lesso
n=114)
if x == y:
return 0
Fixing the elif x < y:
error,
return y - x
Simplification
1 (unit?
unit=95&lesso else:
n=115) return x - y
Elements of a
Refute Which of the following is the most appropriate name for this function?
Problem (unit?
unit=95&lesso abs
n=116) gap_between
Refuting the AbsoluteDifference
median num_integers_between
function (unit?
unit=95&lesso No, the answer is incorrect.
n=117)
Score: 0
Accepted Answers:
Simplification gap_between
2 (unit?
unit=95&lesso 5) Consider the following Python function: 1 point
n=118)
def f(x: int, y: int) -> bool: # Line 1
Feedback for
if y == 0: # Line 2
Refute
result = True # Line 3
Problems
(unit?
elif y != 0: # Line 4
unit=95&lesso if (x % y == 0): # Line 5
n=119) result = True # Line 6
else: # Line 7
Attempting to
result = False # Line 8
refute (unit?
return result # Line 9
unit=95&lesso
n=120)
The above function can be rewritten as:
Refuting the
num_days
def f(x: int, y: int) -> bool: # Line 1
function (unit?
return EXPRESSION
unit=95&lesso
n=121)
where EXPRESSION is:
Critique our
friend's (x % y == 0) or (y == 0)
function (unit?
(x % y == 0) and (y == 0)
unit=95&lesso
n=122) (y == 0) or (x % y == 0)
Boolean/logica (y == 0) and (x % y == 0)
l operators Yes, the answer is correct.
(unit? Score: 1
unit=95&lesso Accepted Answers:
n=123) (y == 0) or (x % y == 0)
Simplification
3 (unit? 6) Refute this ([Link] 1 point
unit=95&lesso Python function by choosing appropriate values of n, expected_answer,
n=124) and return_value.
Identifying an
n = 33
unexpected
behaviour n = -3
(unit? n = 0
unit=95&lesso expected_answer = 0
n=125)
expected_answer = 1
Understanding
expected_answer = 2
and fixing the
error (unit? return_value = 1
unit=95&lesso return_value = 2
n=126)
return_value = 3
Short-circuiting
Yes, the answer is correct.
(unit?
Score: 1
unit=95&lesso
Accepted Answers:
n=127)
n = -3
Inequivalence expected_answer = 1
due to short- return_value = 2
circuiting
(unit? 7) Find the smallest positive integer n that refutes this
unit=95&lesso ([Link] buggy Python function.
n=128)
Your answer should be only the value of n. For example, if you think the value of n is 3, just
Summary
(unit? enter 3 in box below.
unit=95&lesso
n=129) Do not enter things like:
The answer is 3
Quiz: Week 3
Assignment 3
n = 3
(assessment?
121
name=150)
Weekly
Yes, the answer is correct.
Score: 2
Feedback
Accepted Answers:
Form (unit?
(Type: String) 121
unit=95&lesso
n=96) 2 points
Week 4 Part 8) For the smallest positive integer n that refutes this 2 points
1 Helper ([Link] buggy Python function,
functions what are the values of expected_answer, and return_value?
and
recursion () Note: Your answer to this question should be based on your answer to the previous question.
Week 4 Part expected_answer = False
2 Asking
expected_answer = True
Clarifying
Questions () return_value = False
return_value = True
Week 5 Part
Yes, the answer is correct.
1 Lists, Score: 2
Tuples, and Accepted Answers:
Exceptions () expected_answer = False
return_value = True
Week 5 Part
2 Iteration ()
Week 6
Iteration and
Testing ()
Week 7
Learning a
new
language (C)
()
Week 8 Part
1 Strings
and
functions in
C ()
Week 8 Part
2
Demystifying
Python Lists
()
Live Session
()