0% found this document useful (0 votes)
7 views

Assignment 2

The document provides 10 programming problems to solve using Python. The problems involve tasks like calculating expressions, finding areas of triangles, generating and manipulating lists, checking series expansions, and identifying prime numbers.

Uploaded by

sujit basu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Assignment 2

The document provides 10 programming problems to solve using Python. The problems involve tasks like calculating expressions, finding areas of triangles, generating and manipulating lists, checking series expansions, and identifying prime numbers.

Uploaded by

sujit basu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Assignment-2

Write Python Programs to solve the following problems

1. Write a program, which reads two float numbers using input() and prints the product of them in
the form– ‘the product of 2.5 and 4.7 is 11.75’, where the input values are 2.5 and 4.7 respectively.

2.Write a program, which reads 4 numbers a, b, c and x using only one input() and prints the value
of the expression a.cos(x)+b.sin(x)+c. e.g. input 1 2 3 4 output 0.83275.

3. Write a program, which reads a, b and c as sides of a triangle and prints its area. Hint: area
= (s * ( s − a ) * ( s − b ) * ( s − c ) )1/2 , where s is (a+b+c)/2. Input 5 7 10 output should be printed
in the form ‘the area of the triangle having sides of length 5.0,7.0 and 10.0 is 16.248’.

4. Write a program to find the sum 1 + x - 2x2+ 3x3- ... + (-1)n-1nxn , where x and n are provided by
the user. If input x=2 and n=6 output is -269.0.

5. Write a program to find the sum 1 + x /1!+ x 2/2!+ x3/3!+....xn/n! , where x and n are provided by
the user. Note that when n is large the summation tends to e x. e.g. if input x=2 and n=100 output is
approximatly e2 =7.389

6. Write a program to check if cos(x)=1-x2/2!+x4/4!-x6/6!+x8/8!-x10/10!+..... by putting two


different values of x. For e.g. if x=2 and n=100 both sides should give 0.4161468. If x=5 and
n=100 both sides should give 0.283662.

6. Write a program to generate a list having elements 1,4,8,-3,19,0. Do the following operations
sequentially on the list – i) remove element 19 ii) add element 3 at 3rd position (note 0 is the first
position) iii) sort the list in increasing order iv) print the list iv) clear all the elements in the list and
print to show there is no element left.

7. Write a program to generate a list having elements 1,2,3...,n , where n is provided by the user.
Print only the elements that are divisible by 3.

8. Write a program to read n integers from user (using a loop) and store them in a list, where n is
provided by the user. The program outputs the maximum and the second maximum of the elements
in the list. Assume all the elements are unique in the list. For e.g. if a list is [2,9,3,5,0] , max is 9 and
second maximum is 5.

9. Write a program to generate a list having elements starting from a and ending at b with an
increament of 2, i.e. a,a+2,a+4,a+6,....b. Read another integer x. If an element on the list is divisible
by x then modify the element to 1 else make it 0. Finally print the list. For e.g. a=4 and b=15
generates the list [4,6,8,10,12,14]. If x=3, the modified list will be [0,1,0,0,1,0]

10. Write a program to generate a list having elements 1,2,3...,n , where n is provided by the user.
The program generates another list to store all the prime numbers present in the list i.e. 2, 3, 5, 7,
11, ... and finally prints the new list.

You might also like