The Joy of Computing using Python | NPTEL 2023 | Week 3 Assignment Solutions
ABOUT THE COURSE :
A fun filled whirlwind tour of 30 hrs, covering everything you need to know
to fall in love with the most sought after skill of the 21st century. The
course brings programming to your desk with anecdotes, analogies and
illustrious examples. Turning abstractions to insights and engineering to
art, the course focuses primarily to inspire the learner's mind to think
logically and arrive at a solution programmatically. As part of the course,
you will be learning how to practice and culture the art of programming with
Python as a language. At the end of the course, we introduce some of the
current advances in computing to motivate the enthusiastic learner to pursue
further directions.
Course Status : Upcoming
Course Type : Elective
Duration : 12 weeks
Start Date : 23 Jan
2023
End Date : 14 Apr 2023
Exam Date : 29 Apr 2023 IST
Enrollment Ends : 30 Jan 2023
CRITERIA TO GET A CERTIFICATE :
Average assignment score = 25% of average of best 8 assignments out of the
total 12 assignments given in the course.
Exam score = 75% of the proctored certification exam score out of 100
Final score = Average assignment score + Exam score
YOU WILL BE ELIGIBLE FOR A CERTIFICATE ONLY IF AVERAGE ASSIGNMENT SCORE
>=10/25 AND EXAM SCORE >= 30/75. If one of the 2 criteria is not met,
you will not get the certificate even if the Final score >= 40/100.
NOTE: Please note that there will not be an unproctored programming exam
for this course this term.
The Joy of Computing using Python Week 3 Assignment Solutions :-
Q1)
_____ is the method to insert an item into a specified position in a
list.
a) Push
b) Write
c) Insert
d) All of the above
Answer :- (c) Insert
Q2)
Which method returns the number of occurrences of an element in a
list.
a) Number of
b) Total
c) Count
d) Length
Answer :- (c) count
Q3) The function random.randint(1,100) in python generates.
a) A random integer between 1 to 100 with 1 and 100 both inclusive
b) A random integer between 1 to 100 with 1 and 100 both exclusive
c) A random integer between 1 to 100 with only 100 inclusive
d) None of the above
Answer :-
(a) A random integer between 1 to 100 with 1 and 100 both inclusive
Q4) The method open(“file1.txt”, r+) opens the file file1.txt in
______.
a) Read only mode
b) Write only mode
c) Read Write mode
d) None of the above
Answer :- (c) Read Write mode
Q5) Consider the list L= [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]. What will
be the output of the statement L [3:6]?
a) [2, 3, 5]
b) [0, 1, 1]
c) [1, 2, 3]
d) none
Answer :- (a) [2, 3, 5]
Q6) What is the output of this code?
a) 0
b) 1
c) 2
d) This code will raise a runtime error
Answer :- (a) 0
Q7) What is the output of the following code?
Answer :- 1
Q8) What is the output of the following code?
a) False True
b) True False
c) True True
d) False False
Answer :- (a) False True
Q9) Explain what the output will be when the code given below is
executed.
a) The program throws an error
b) 5
c) 5.5
d) 4.5
Answer :- (d) 4.5
Q10) Which among the following statements is True with respect to the
code given below?
a) count=50
b) The following code throws up an error.
c) count=550
d) count=450
Answer :- (d) count=450
Week 3 Programming Assignment 1 :-
Take an input N as an integer and write a program to display a right
angle triangle with N rows and N columns.
Input : 5
Ouput :
*
* *
* * *
* * * *
* * * * *
Code
:-
Week 3 Programming Assignment 1
N=int(input()) for i in range(1,N+1): for j in range(1,i+1): print("* ",end="") if j!=N: print()
Week 3 Programming Assignment 2 :-
Write a program to take an input N and print Fibonacci sequence till N
terms.
The Fibonacci sequence is a set of integers (the Fibonacci numbers)
that starts with a zero, followed by a one, then by another one, and
then by a series of steadily increasing numbers. The sequence follows
the rule that each number is equal to the sum of the preceding two
numbers.
Input
7
Output
0
1
1
2
3
5
8
Code :-
Week 3 Programming Assignment 2
N=int(input()) L=[0,1] if N==1: print(0) elif N==2: print(0) print(1) else: print(0) print(1) for i in range(N-2): if i==N-3: print(L[-1]+L[-2],end="") else: print(L[-1]+L[-2]) L.append(L[-1]+L[-2])
Week 3 Programming Assignment 3 :-
Take base B and height H as an input and write a program to print a
parallelogram.
Input :
8
4
Output :
********
********
********
********
Code :-
Week 3 Programming Assignment 3
B=int(input()) H=int(input()) for i in range(H): for j in range(B): print('*',end="") if i!=H-1: print()
Follow Us