Lec14FileWhile

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

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

View Full Document Right Arrow Icon
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):
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.

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 Right Arrow Icon
Ask a homework question - tutors are online