COL100 Assignment 2 Solved

30.00 $

Category: Tags: , ,
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

Rate this product

This assignment relies heavily on the Python input and print functions, make sure you under- stand how to use them. It also tests your understanding on basic variable handling required in programming.

1 Basic Calculator (5 marks, In-Lab component)

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

OUTPUT:

1 2 3 4 5

INPUT: 1

2

OUTPUT:

1 2 3 4 5

2 4

6 -2 8 0.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:

1 2

3 -1 2 0.5 1

2 Print Area (5 marks)

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:

2

4 10 3 9 2 8 5 9 7

1 2 3 4 5 6 7 8 9

OUTPUT:

1 2 3 4 5

50.24
100
27
16
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 2 3 4 5 6 7 8 9

OUTPUT:

1 2 3 4 5

5 5 4 6 3 4 11 10 5

78.5
25
24
12
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.

􏰅ni=1 ci · gi
SGPA= 􏰅n c (1)

i=1 i

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.

3

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

INPUT:

1 2 3 4 5 6 7 8 9

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 2 3 4 5 6 7 8 9

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
10
3
9
2
8
5
9
2
10

5 0 4 0 3 0 2 0 1 10

4

  • A2-ur8shw.zip