0% found this document useful (0 votes)
7 views4 pages

Programming with Generative AI Course

The document outlines the structure and content of the Week 8 Assignment for the NPTEL course 'Programming with Generative AI'. It includes details on submission deadlines, assignment questions, and accepted answers for various programming concepts in Python and C. The assignment focuses on translating functions between the two languages and understanding their syntax and semantics.

Uploaded by

Prashanth H A
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)
7 views4 pages

Programming with Generative AI Course

The document outlines the structure and content of the Week 8 Assignment for the NPTEL course 'Programming with Generative AI'. It includes details on submission deadlines, assignment questions, and accepted answers for various programming concepts in Python and C. The assignment focuses on translating functions between the two languages and understanding their syntax and semantics.

Uploaded by

Prashanth H A
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

X

([Link] ([Link]

prashanth049@[Link] 

NPTEL ([Link] » Programming with Generative AI (course)

Course Week 8 Assignment 8


outline The due date for submitting this assignment has passed.
Due on 2025-10-15, 23:59 IST.
Week 1 ()

How does an
Assignment submitted on 2025-10-13, 19:56 IST
NPTEL 1) Your friend is familiar with programming language A and is keen to learn a new 1 point
online programming language B. The two languages have similar syntax.
course
work? () Your friend is most likely to struggle if statements and expressions with similar BLANK1 in the
two languages have BLANK2 BLANK3.
Week 1 Part
1 What are the most appropriate values of BLANK1, BLANK2, and BLANK3?
Introduction
() BLANK1 is: syntax
BLANK1 is: semantics
Week 1 Part
BLANK2 is: similar
2 Getting
started with BLANK2 is: different
Python () BLANK3 is: syntax
BLANK3 is: semantics
Week 2 Part
1 Variables No, the answer is incorrect.
Score: 0
and
Accepted Answers:
Assignments
BLANK1 is: syntax
()
BLANK2 is: different
BLANK3 is: semantics
Week 2 Part
2 Functions
2) Consider this Python function: 1 point
and Simple
Programs ()
1: def sorted_ascending(data: list[int]) -> bool:
2: i = 0
3: while i < len(data) - 1:
Week 3 Part
4: if data[i] > data[i + 1]:
1 User-
5: return False
defined
6: i += 1
functions ()
7: return True

Week 3 Part
Select the most appropriate versions of the points below that your friend should keep in mind
2 Refuting
and while translating this function into C:
debugging
(Line 1) The parameter must be of type int *
complex
functions () (Line 1) The parameter should be of type const int *
(Line 1) The function return type must be of type int
Week 4 Part
(Line 1) An extra parameter is necessary
1 Helper
functions (Line 2) The type of variable i must be specified
and (Line 2) If the type of variable i is int, the variable is automatically initialized to 0
recursion () (Line 3) The condition of the while-loop must be within parentheses (...)
(Line 3) The condition of the while-loop should be within parentheses (...)
Week 4 Part
2 Asking (Line 3) The condition of the while-loop depends on an extra parameter
Clarifying (Line 4) The if-condition must be within parentheses (...)
Questions ()
(Line 4) The if-condition should be within parentheses (...)

Week 5 Part (Line 6) The assignment statement must be written as: i++
1 Lists, (Line 6) The assignment statement should be written as: i = i++
Tuples, and
Although Python allows multiple return statements within a function, C does not
Exceptions ()
Although a return statement immediately exits a Python function, the same does not
Week 5 Part hold for C
2 Iteration () No, the answer is incorrect.
Score: 0
Week 6 Accepted Answers:
Iteration and (Line 1) The parameter should be of type const int *
Testing () (Line 1) An extra parameter is necessary
(Line 2) The type of variable i must be specified
Week 7 (Line 3) The condition of the while-loop must be within parentheses (...)
Learning a (Line 3) The condition of the while-loop depends on an extra parameter
new (Line 4) The if-condition must be within parentheses (...)
language (C)
() 3) Consider this C function: 1 point

Week 8 Part 1: int avg(const char *s) {


1 Strings 2: int total = 0;
and 3: int i = 0;
functions in 4: while (s[i]) {
C () 5: total += s[i];
6: i++;
Week 8 Part 7: }
2 8: return total / i;
Demystifying 9: }
Python Lists Select the most appropriate versions of the points below that your friend should keep in mind
() while translating this function into Python:

Algorithm- (Line 1) The type-hint for parameter s should be str


centric
Lines 2 to 7 cannot be written using a for-loop
improvements
(to_ind_lower) Lines 2 to 7 should not be written using a for-loop
(unit?
(Line 4) Can be translated as: while i:
unit=265&less
on=266) (Line 4) Can be translated as: while s[i]:
(Line 4) Can be translated as: while i < len(s):
Data-centric
improvements (Line 4) Can be translated as: while i <= len(s):
(to_ind_lower) (Line 5) Can be translated as: total += s[i]
(unit?
unit=265&less (Line 5) Can be translated as: total += int(s[i])
on=267) (Line 5) Can be translated as: total += ord(s[i])

Processing (Line 8) Can be translated as: return total / i


textual data: C (Line 8) Can be translated as: return total // i
or Python
(unit? (Line 8) Can result in a divide by zero error (only in C)
unit=265&less (Line 8) Can result in a divide by zero error (only in Python)
on=268)
(Line 8) Can result in a divide by zero error (in both C and Python)
Understanding No, the answer is incorrect.
(simplified) Score: 0
Python lists Accepted Answers:
(unit? (Line 1) The type-hint for parameter s should be str
unit=265&less
(Line 4) Can be translated as: while i < len(s):
on=269)
(Line 5) Can be translated as: total += ord(s[i])
A simple (Line 8) Can be translated as: return total // i
implementatio (Line 8) Can result in a divide by zero error (in both C and Python)
n of Python
lists (Part 1) 4) A popular implementation of Python is CPython, where list objects are internally 1 point
(unit? represented as C arrays.
unit=265&less
on=270) Select all sentences that help explain why the [Link] method is fast in practice?
A simple
implementatio
C arrays can grow as long as necessary
n of Python C code runs much slower than Python code
lists (Part 2)
Each call to the Python append requires resizing the underlying C array
(unit?
unit=265&less The C array can be efficiently resized using malloc
on=271) The C array can be efficiently resized using realloc
A simple No, the answer is incorrect.
implementatio Score: 0
n of Python Accepted Answers:
lists (Part 3) The C array can be efficiently resized using realloc
(unit?
unit=265&less
on=272)

A simple
implementatio
n of Python
lists (Part 4)
(unit?
unit=265&less
on=273)

Testing the list


implementatio
n (unit?
unit=265&less
on=274)

Summary
(unit?
unit=265&less
on=275)

Quiz: Week 8
Assignment 8
(assessment?
name=277)

Weekly
Feedback
Form (unit?
unit=265&less
on=134)

Live Session
()

You might also like