Hello everyone, we are came back with Nptel week 2 programming assignment of Joy Of Computing Using Python. In this article we will discuss the answers fo week 2 assignment . Please Use these answers as reference, If any doubt arises feel free to comment in the comment section below. Then why Waiting, Come with us, Let us solve the programming assignment.Â
Join Telegram:Â Â CLICK HEREÂ
Also Read:Â NPTEL JOY OF COMPUTING USING PYTHON WEEK 2 ASSIGNEMNTÂ
NPTEL Joy Of Python Using Python Week 2 Programming Assignment 2024
Last Date: 08-08-2024
Q1. Create a Python program that calculates the absolute value of a given number.
The program should prompt the user to input a number, then compute and print the absolute value of that number.
Input Format-
The input consists of single number.
Output Format-
The output consists of absolute value of the input.
Example-
Input:
-6
Output:
6
Answer:Â
a = int(input())num=abs(a)print(num) {codeBox}Â
Q2. Create a Python program to determine the nth element of an arithmetic sequence where the first term a is 7 and the common difference d is 11. The program should prompt the user to input the value of n, then compute and print the nth element of the sequence.
Input Format:
The input consists of a single integer n.
Output Format:
The output consists of the nth element of the arithmetic sequence.
Example:
Input:
3
Output:
29
Answer:Â
def AP(a, d, N) :Â Â return (a + (N - 1) * d)Â Â ÂN = int(input())Âprint(AP(a, d, N)) {codeBox}
Q3.Â
Question:
Create a Python program to compute the sum of the first N natural numbers {1,2,3...N}. The program should prompt the user to input the value of N, then compute and print the sum of the first N natural numbers.
Input Format:
The input consists of a single integer N.
Output Format:
The output consists of the sum of the first N natural numbers.
Example:
Input-
5
Output-
15
Answer:Â
num = int(input())if num < 0:  print("Enter a positive number")else:  sum = 0 Âwhile(num > 0):   sum += num   num -= 1print(sum,end=" ") {codeBox}
Conclusion
If any changes in the answer, please visit the website on or before to the last date.Â
Join Telegram:Â Â CLICK HEREÂ Â