a9q4 - # CS 116 Ru Wang r46wang 20319247 # Assignment 9...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
## CS 116 Ru Wang r46wang 20319247 ## Assignment 9 Question 4 ## print_complete_drawing: string -> none ## purpose: this function takes in a string representing the name of the file and produces nothing ## effects: it prints out the complete drawing to inputted incomplete symmetric ASCII drawing ## the function will display "Could not open the file" if an invalid file is entered ## examples: ## print_complete_drawing("hi") would print "Could not open the file" ## print_complete_drawing("a9q4_owl.txt") would display ## (o_o) ## (( )) ## ^ ^ ## to the file inputted a9q4_owl.txt that contains: ## ( _o ## ( ) ## ^ def print_complete_drawing(filename): try: f = file(filename, 'r') except: print "Could not open the file" return mirrordict = {'(': ')', ')': '(', '{': '}', '}': '{', '>': '<', '<': '>', '/': '\\', '\\': '/'} flines = f.readlines() for line in flines: length = len(line)-1 if length % 2 == 0: n = length/2 a = n - 1 else: n = length/2+1 a = n - 2 firsthalf = "" secondhalf = "" while n < length:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/21/2010 for the course CS 116 taught by Professor T.vasiga during the Fall '09 term at Waterloo.

Page1 / 2

a9q4 - # CS 116 Ru Wang r46wang 20319247 # Assignment 9...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online