Python Programming

profileKpl
assigment7.py

import string import random try: searchKey_f = open("homework7wordSearchKey.txt","r") except: print("searchKey_f target file not opened.") else: print("searchKey_f target file opened.") try: searchPuzzle_f = open("homework7wordSearchPuzzle.txt","w") except: print("searchPuzzle_f not opened.") else: print("searchPuzzle_f opened.") keyBlock_s = searchKey_f.read() searchKey_f.close() print(keyBlock_s) puzzleBlock_s = "" for character_c in keyBlock_s: if character_c == " ": puzzleBlock_s += random.choice(string.ascii_uppercase) else: puzzleBlock_s += character_c print(puzzleBlock_s) searchPuzzle_f.write(puzzleBlock_s) try: searchKey_f.close() searchPuzzle_f.close() except: print("Did not close files") else: print("Closed files.")