You are on page 1of 2

The British College

Fundamentals of Data Science Level 3

Assignment 3

1. Handle the exception thrown by the code below by using try and except blocks.

for i in ['a','b','c']:
print(i**2)

2. Write a function that asks for an integer and prints the square of it. Use a while loop with a try,
except, else block to account for incorrect inputs.

This should be the output of your function:

Input an integer: “hello”


Unrecognized number! Please try again!
Input an integer: 2
You entered 2, your number squared is: 4

3. Complete the Line class given below. Your class should accept two sets of coordinate points as
tuples. Write two methods within the class, one to compute distance between two points, and
another to compute the slope.

You have to complete the code given below:

class Line:
def __init__(self,coordinateA,coordinateB):
pass

def distance(self):
pass

def slope(self):
pass

Example output:

c1 = (3, 2)
c2 = (8, 10)

myline = Line(c1, c2)

4. Complete the class given below:

class Cylinder:

def __init__(self,height=1,radius=1):
pass

def volume(self):
pass

def surface_area(self):
pass
5. Define a class InputOutString which has at least two methods: getString: to get a string from
console input, printString: to print the string in upper case. Also please include simple test function
to test the class methods.

6. Write a python program to copy the contents of one file to another. Your new file should be
named as old file name followed by a 1. For example: if your original file is named: myfile.txt, your
new file should be named: myfile1.txt

7. Write a lambda function that takes in two numbers, and returns the sum of the squares of the
input numbers.

Example: If your input is 2, 3, your output should be : 22 + 32 i.e. 13

You might also like