[SOLVED] COL100 Assignment 2

30.00 $

Category:

Description

Rate this product

1 Basic Calculator

Write a python program to perform the following binary operations on two integers a and b:

  • Addition
  • Subtraction
  • Multiplication
  • Division
  • Modulus

Your program should prompt the user to enter the two numbers, namely a and b (You can assume that

b = 0

̸ ).Note: a, b are not necessarily integers and can take any real value.

Example 1:

INPUT:

1 2

2 4

OUTPUT:

1 6

2 -2

3 8

4 0.5

5 2

EXPLANATION:

Here in this example we are provided with two numbers, a = 2 and b = 4. So, there addition will be

a + b = 6, their subtraction will be a b = 2, their multiplication will be a b = 8, their division will

be a/b = 0.5 and their modulus will be a%b = 2.

Example 2:

INPUT:

1 1

2 2

OUTPUT:

1 3

2 -1

3 2

4 0.5

5 1

2 Print Area 

Write a single program to compute the area of the following:

  • Circle: Input the radius and print the area.
  • Square: Input the length of a side and print the area.
  • Rectangle: Input the length and breadth and print the area.
  • Parallelogram: Input the base and height, and print the area.
  • Trapezium: Input the length of the parallel sides, and the perpendicular distance between them

and print the area.

Your program should prompt the user to enter 9 numbers. First will be the radius of circle, second will

be length of a side in square, third will be length of rectangle, fourth will be breadth of rectangle, fifth

will be base of parallelogram, sixth will be height of parallelogram, seventh and eighth will be length

of parallel sides of trapezium and ninth will be perpendicular distance between the parallel sides of

trapezium. Note: Take value of π as 3.14.

Note: All the above numerical quantities can take any real value.

Example 1:

INPUT:

21 4

2 10

3 3

4 9

5 2

6 8

7 5

8 9

9 7

OUTPUT:

1 50.24

2 100

3 27

4 16

5 49.0

EXPLANATION:

Following are the calculations involved in above example:

π · r2 = 3.14 · 4 · 4 = 50.24

a2 = 102 = 100

a · b = 3 · 9 = 27

a · h = 2 · 8 = 16

h · (a + b)/2 = 7 · (5 + 9)/2 = 49.0

Example 2:

INPUT:

1 5

2 5

3 4

4 6

5 3

6 4

7 11

8 10

9 5

OUTPUT:

1 78.5

2 25

3 24

4 12

5 52.5

3 What’s my SGPA for this semester ? (5 marks)

Write a python program to compute SGPA for a given semester. Recall that if you took n courses in

a semester with credits c1, c2 . . . cn and you got g1, g2 . . . gn grades in these courses respectively, your

SGPA is calculated as the weighted mean of these grades i.e.

SGP A =

P n

i=1 ci · gi

P n

i=1 ci

(1)

However, for this problem, we will assume that you took n = 5 courses in a semester. The program

should accept as input, credits and grades obtained for each of these 5 courses and then output the

final SGPA for the semester. For each of the 5 courses, we provide the credits and grade obtained in

that course, each in a new line.

3Note: It is guaranteed that credits and grades obtained are both integers.

Example 1:

INPUT:

1 4

2 10

3 3

4 9

5 2

6 8

7 5

8 9

9 2

10 10

OUTPUT:

1 9.25

EXPLANATION:

Following are the credits and grades obtained in 5 courses:

c1 = 4, g1 = 10

c2 = 3, g2 = 9

c3 = 2, g3 = 8

c4 = 5, g4 = 9

c5 = 2, g5 = 10

So, the final SGPA obtained is 9.25.

Example 2:

INPUT:

1 5

2 0

3 4

4 0

5 3

6 0

7 2

8 0

9 1

10 10

OUTPUT:

1 0.66

EXPLANATION:

c1 = 5, g1 = 0

c2 = 4, g2 = 0

c3 = 3, g3 = 0

c4 = 2, g4 = 0

c5 = 1, g5 = 10

SGPA obtained is 0.66.

4