LAB ASSIGNMENT – 2
Programming in Python ([Link]. 4th Semester)
Objec ve:
To develop problem-solving skills and gain hands-on experience with basic programming constructs
such as loops, condi onals, and mathema cal computa ons.
Q1. Write a program to display your name 10 mes using:
(a) a for loop
(b) a while loop
Q2. Write a program to calculate the sum of the first n natural numbers, where n is provided by the
user.
Q3. Write a program to compute the factorial of a given number.
Q4. Write a program to display the mul plica on tables from 1 to 10.
Q5. Write a program to find the sum of squares of the first n odd numbers.
Q6. Write a program to display the Fibonacci series up to the n-th term.
Q7. Write a program to display all factors of a given number.
Q8 Write a program to check whether a given number is prime or composite.
Q9. Write a program that takes an integer as input and determines the total number of digits
present in the number.
(Example: For input 13452, the output should be 5.)
Q10. Write a program to verify whether the inpu ed number is a palindrome. (Example: For input
13231 is a palindrome but 12345 is not a palindrome)
Q11. Write a program that takes two numbers as input and computes their Greatest Common Divisor
(GCD).
Q12. Write a program that takes two numbers as input and computes their Least Common Mul ple (LCM).
Q13. Write a program to display all prime numbers between m and n, where m < n.
Q14. Write a program to display the factors of a given number.
Q15. Write a program to find and display the prime factors of a given number.
Q16. Write a Python program to evaluate the exponen al series.
i.e. ex = 1+ X + X^2/2! + X^3/3! + …………..
The program should compute the value of 𝒆𝒙 up to a specified number of terms.
Q17. Write a Python program to evaluate the exponen al series using its series expansion. (Taylor
series expansion)
i.e sin(X) = X – X3/3! + X5/5! - …………………..
The program should compute the value of sin(x) up to a specified number of terms.
Q18. Write a Python program that will evaluate the sin(x) series
(Hints Use Taylor series expansion)
i.e cos(X) = 1-X^2/2! + X4/4! – X6/6! - …………………..
The program should compute the value of cos(x) up to a specified number of terms.
Q19. Write a program to find all numbers less than a given number 𝑁that are coprime with 𝑁.
(Note: A pair (𝑎, 𝑏)is said to be coprime if gcd (𝑎, 𝑏) = 1.)
Q20. Given a number 𝑁, write a program to determine the number of coprime pairs (𝑎, 𝑏)such that:
1 ≤ 𝑎, 𝑏 ≤ 𝑁
𝑎×𝑏 =𝑁
gcd (𝑎, 𝑏) = 1
21. Write a C program to convert Decimal to Binary number system.
22. Write a C program to convert Binary to Decimal number system.
Assignment of Pa ern.
Q23. Write a program that will display the pa ern as follows:
Q24. Write a program that will display the pa ern as follows