Professional Documents
Culture Documents
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.
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.
class Line:
def __init__(self,coordinateA,coordinateB):
pass
def distance(self):
pass
def slope(self):
pass
Example output:
c1 = (3, 2)
c2 = (8, 10)
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.