Lec14FileWhile

# Lec14FileWhile - 1 2 4 8 2^n sum = 0 addvalue = 1 for index...

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

1+2+4+8+…+2^n sum = 0 addvalue = 1 for index in range(n+1): sum = sum + addvalue addvalue = addvalue * 2 return sum sum = 0 for index in range(n+1): sum = sum + (2 ** index) def rot(plain): cipher = “” rotate = 1 for ch in plain: index = ord(ch) – ord(‘a’) index = (index + rotate) %26 ch = chr(index + ord(‘a’)) cipher = cipher + ch rotate = rotate + 1 return cipher def countItems(myList, item): count = 0 for element in myList: if (element == item): count = count + 1 return count Opening files: filename = input(“Enter filename: “) file = open(filename,”r”) #for line in file: # print(line) lines = file.readlines() # places each line in a different spot in the list file.close() # print out ONLY the comments in a python file def printComments(lines): “”” printComments lines – a list containing strings, each string is one line of the file “”” for line in lines: if (‘#’ in line): print(line) if (‘”””’ in line): print(line) if (inFunctionHeader == True):

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 12/27/2011 for the course CMPSC 8 taught by Professor Franklin during the Fall '09 term at UCSB.

### Page1 / 3

Lec14FileWhile - 1 2 4 8 2^n sum = 0 addvalue = 1 for index...

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

View Full Document
Ask a homework question - tutors are online