ࡱ> SUR bjbjGG ..--$$<.... "+ 7W<Y<Y<Y<Y<Y<Y<,>A~<?  ??<..<?..W<?W<R9;0V\|89C<<0<:BB<;;6;P???<<???<B????????? :   CSE 231 Spring 2013 COMPUTER PROJECT #7 Assignment Overview This program focuses on the use of strings, lists, files and their various operators. It also incorporates a number of things we have learned about loops, if statements and functions. This assignment is worth 50 points (4% of course grade), and must be submitted before 11:59 PM on Monday, March 11th . Background An Internet meme made the rounds in the early 2000's concerning some quirks about how human beings read a sentence. Below was the paragraph that was used in the meme. Can you read it? Can you tell what is "wrong" with the words? Aoccdrnig to rscheearch at an Elingsh uinervtisy, it deosnt mttaer in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is taht the frist and lsat ltteer is at the rghit pclae. The rset can be a toatl mses and you can sitll raed it wouthit a porbelm. Tihs is bcuseae we do not raed ervey lteter by itslef but the wrod as a wlohe. If you keep the first letter and the last letter of a word in their correct positions, then scramble the letters in between, the claim was that people could still read the words. It was, however, not a legitimate research claim as the meme lead you to believe. In fact, the process of scrambling as indicated above does not work for words that have a longer length. The web site  HYPERLINK "http://www.balancedreading.com/cambridge.html" http://www.balancedreading.com/cambridge.html shows some counter examples (as well as debunks the research claims) for this kind of reading comprehension. We are going to imitate the scrambling process on some files of English text: some with long words and some without, to test the claim. Program overview: You will write a program that: prompt for the name of a file of English text to read in and a file to write out your results constant prompting required for the file to be read. read each line of the file perform the scrambling operation on each word of the line, preserving the non-word features (see details below) output the scrambled line to the indicated output file. Program specifications scramble_word(word_str) returns string. This function takes in a single word from the file and returns a scrambled word according to the following rules: The first and last letter are preserved in the original positions Seems like a waste to shuffle something of length 3 or less Furthermore, if there are punctuation marks associated with the word, then those positions are preserved as well. For example, a scrambling of the word "finished." could be "fnsieihd." but not "fsndi.hd". The period would have to be in the same place. Same for commas and other punctuation marks. Look at the examples scramble_line(line_str) returns string. This function takes in an entire line of text and returns a new line with each word scrambled using the above function scramble_word . open_read_file(file_name_str) returns file_object. This function takes a file string, the name of a file to be opened for reading. It contiguously prompts until it can open a file. It then returns the opened file_obj . main(): prompts for a file to write prompts for a file to read, calls open_read_file with that string. using the file_obj returned from open_read_file : for each line in the file: get a scrambled line by calling scramble_line function write the scramble line to the output file_obj. Deliverables: proj07.py -- your source code solution Please be sure to use the specified file name, and to submit your file for grading via the "handin" program (http://www.cse.msu.edu/handin/webclient). Save your file to your CSE disk (H drive on CSE computers) -- archiving files on the CSE disk is the only evidence that you have completed the project, if something has gone wrong. Get a TA to help you do this, if you do not know how. Assignment Notes: Be smart!!! Implement the first function scramble_word and test it on individual words. Then write scramble_line and test it with a single line of text. Remember, it uses scramble_word to accomplish its goal. Do the main function last, as this ties everything together. We need a way to scramble some letters. Conveniently there is a method in the random module called shuffle. It takes a list as an argument and shuffles (re-arranges) the positions of the elements of the list in-place. It doesn't have a return value. Here are some examples: import random my_list = [1,2,3,4,5] random.shuffle(my_list) print(my_list) ( [2, 4, 3, 1, 5] The shuffle method only works on a mutable, so you cannot shuffle a string. Thus we have to move back and forth between a string and a list. Here are some relevant methods. you can convert a string to a list, using the list function. This function requires an iterable argument and adds each element of the iterable (each character of a string) as an element to a list my_str = "hi mom" my_list = list(my_str) print(my_list) ( ['h', 'i', ' ', 'm', 'o', 'm'] the join method of strings concatenates elements of a list (if the elements characters, an important point to remember) together as a single string. It uses the calling string as what to put between each element. For example: my_list = ['h', 'i', ' ', 'm', 'o', 'm'] my_str = ''.join(my_list) # use empty string to join print(my_str) ( 'hi mom' my_str = ','.join(my_list) # use comma to join my_str ( 'h,i, ,m,o,m' Notice the comma is not added at the end of a join. That can be very useful. Look at listStr.py in the project directory I]q+ E ( T r k l m y EGIc~옱hm =hVNPJhKhVN0JPJjhKhVNPJUh8r#hVNPJjhVNPJUhm =hVNB*OJQJphfff hBkPJ h !PJhhH*PJ hPJ hPJ hVNPJhVNhd hdPJ1HI]qr* + FG` & F gd & F gdgdgdVNdgdVNgdVNS_ &XY\sOhuyILQSTo}ôִִִִִִ֮֨֨ք hSPJhShSOJPJQJ^JhShFOJPJQJ^J hFPJ h PJh !h !OJPJQJ^Jh !h !5PJhhPJ h !PJ h=PJ hPJ hVNPJh5PJ\hVN5PJ\4 XYZ[\s OyT\x?o}~ & F gdS & F gdS & F gdS & F gd ! & F gd !^gd & F gd}~.@AjwP (abdklm01iǻzteh?hSOJPJQJ^J h?PJhBEhVNOJPJQJ h?|PJ" jhShSOJPJQJ^JhShS56>*PJhShSOJPJQJ^Jh=OJPJQJ^Jh !h=OJPJQJ^Jh=h=OJPJQJ^J h=PJhVN5PJ\ hSPJ hVNPJ'~AB-.@APbpm1CZl^gdS8^8gdS & F gd= & F gd=gd=gdVN & Fh^hgdVNijklv);<^ٵyhz /hVNPJ h>HPJ h?|PJ" jh?h?OJPJQJ^Jh?OJPJQJ^Jh?h?PJh?h?OJPJQJ^J hVNPJh?|h?OJPJQJ^J h?PJh?hSOJPJQJ^J" jh?hSOJPJQJ^Jl*<gd>H^gd?|,1h/ =!'"'#$% -DyK .http://www.balancedreading.com/cambridge.htmlyK \http://www.balancedreading.com/cambridge.html666666666vvvvvvvvv666666>6666666666666666666666666666666666666666666666666hH6666666666666666666666666666666666666666666666666666666666666666666666666662 0@P`p2( 0@P`p 0@P`p 0@P`p 0@P`p 0@P`p 0@P`p8XV~_HmH nH sH tH @`@ NormalCJ_HaJmH sH tH >@>  Heading 1$@& 5PJ\D@D  Heading 2$$@&a$ 5PJ\DA`D Default Paragraph FontViV  Table Normal :V 44 la (k (No List DZ@D Plain TextCJOJQJ^JaJ6U@6 m = Hyperlink >*B*phFVF 8r#0FollowedHyperlink >*B*phPK!pO[Content_Types].xmlj0Eжr(΢]yl#!MB;.n̨̽\A1&ҫ QWKvUbOX#&1`RT9<l#$>r `С-;c=1g~'}xPiB$IO1Êk9IcLHY<;*v7'aE\h>=^,*8q;^*4?Wq{nԉogAߤ>8f2*<")QHxK |]Zz)ӁMSm@\&>!7;wP3[EBU`1OC5VD Xa?p S4[NS28;Y[꫙,T1|n;+/ʕj\\,E:! t4.T̡ e1 }; [z^pl@ok0e g@GGHPXNT,مde|*YdT\Y䀰+(T7$ow2缂#G֛ʥ?q NK-/M,WgxFV/FQⷶO&ecx\QLW@H!+{[|{!KAi `cm2iU|Y+ ި [[vxrNE3pmR =Y04,!&0+WC܃@oOS2'Sٮ05$ɤ]pm3Ft GɄ-!y"ӉV . `עv,O.%вKasSƭvMz`3{9+e@eՔLy7W_XtlPK! ѐ'theme/theme/_rels/themeManager.xml.relsM 0wooӺ&݈Э5 6?$Q ,.aic21h:qm@RN;d`o7gK(M&$R(.1r'JЊT8V"AȻHu}|$b{P8g/]QAsم(#L[PK-!pO[Content_Types].xmlPK-!֧6 -_rels/.relsPK-!kytheme/theme/themeManager.xmlPK-!!Z!theme/theme/theme1.xmlPK-! ѐ'( theme/theme/_rels/themeManager.xml.relsPK]# .}i~llX8@0(  B S  ? _Hlt223163874@  #(-267=HMNSY]glmq~s9 A M U h u y I Q ( 5 e m  jwpw17CJRX`grsxyls}~ #(<B_E`h &s{ q w y } N S T X \ c x   ? D bhprmp13CEZ_ln::::::::::::::::::::::::::::::::::: >w[b_ !P *([WZA`vbk2no-6 [L1`r\;q@P^7GbQN>6x4n|qh^`OJQJo(hHh^`OJQJo(hHohp^p`OJQJo(hHh@ ^@ `OJQJo(hHh^`OJQJo(hHoh^`OJQJo(hHh^`OJQJo(hHh^`OJQJo(hHohP^P`OJQJo(hHh ^`hH.h ^`hH.h pL^p`LhH.h @ ^@ `hH.h ^`hH.h L^`LhH.h ^`hH.h ^`hH.h PL^P`LhH.h h^h`hH.h 8^8`hH.h L^`LhH.h  ^ `hH.h  ^ `hH.h xL^x`LhH.h H^H`hH.h ^`hH.h L^`LhH. ^`o(hH. ^`hH. pL^p`LhH. @ ^@ `hH. ^`hH. L^`LhH. ^`hH. ^`hH. PL^P`LhH.h hh^h`hH.h 88^8`hH.h L^`LhH.h   ^ `hH.h   ^ `hH.h xLx^x`LhH.h HH^H`hH.h ^`hH.h L^`LhH.h^`OJQJo(hHh^`OJQJ^Jo(hHohpp^p`OJQJo(hHh@ @ ^@ `OJQJo(hHh^`OJQJ^Jo(hHoh^`OJQJo(hHh^`OJQJo(hHh^`OJQJ^Jo(hHohPP^P`OJQJo(hHhh^h`CJOJQJo(hH^`OJQJo(hHop^p`OJQJo(hH@ ^@ `OJQJo(hH^`OJQJo(hHo^`OJQJo(hH^`OJQJo(hH^`OJQJo(hHoP^P`OJQJo(hHh hh^h`hH.h 88^8`hH.h L^`LhH.h   ^ `hH.h   ^ `hH.h xLx^x`LhH.h HH^H`hH.h ^`hH.h L^`LhH.h^`OJQJo(hHh^`OJQJo(hHohp^p`OJQJo(hHh@ ^@ `OJQJo(hHh^`OJQJo(hHoh^`OJQJo(hHh^`OJQJo(hHh^`OJQJo(hHohP^P`OJQJo(hH^`o(. ^`hH. pL^p`LhH. @ ^@ `hH. ^`hH. L^`LhH. ^`hH. ^`hH. PL^P`LhH.h ^`hH.h ^`hH.h pLp^p`LhH.h @ @ ^@ `hH.h ^`hH.h L^`LhH.h ^`hH.h ^`hH.h PLP^P`LhH.h hh^h`hH.h 88^8`hH.h L^`LhH.h   ^ `hH.h   ^ `hH.h xLx^x`LhH.h HH^H`hH.h ^`hH.h L^`LhH. vbko-QNr\;[L1 *b_ ^7G>wq@4n|q[W                            @dR                                                                      LP_dWdd_dW 4VNdBk?|? = !S>HF@@UnknownG*Ax Times New Roman5Symbol3 *Cx ArialG5  jMS Mincho-3 fgE  Lucida Console? *Cx Courier New;WingdingsA$BCambria Math"Ah{ɳ t=y '=y ''243QH(?m =2 ,CSE 231 d cherba Bill Punch<          Oh+'0 $0 T ` l x'CSE 231  d cherba Normal.dotm Bill Punch11Microsoft Macintosh Word@{4@d^5@$^@s8=y ՜.+,D՜.+,D hp|  'DMC'  CSE 231 Title 8@ _PID_HLINKS'AmE.http://www.balancedreading.com/cambridge.html !"#$%&'()*+,-./0123456789:;<=>?@ACDEFGHIKLMNOPQTRoot Entry F\|8VData 1Table NBWordDocument..SummaryInformation(BDocumentSummaryInformation8JCompObj` F Microsoft Word 97-2004 DocumentNB6WWord.Document.8