ࡱ> EGD#` bjbj\.\. *>D>D t !, 52>!>!>!>!>!"""?5A5A5A5A5A5A5$6hZ9e5"""""e5>!>!Iz5###"">!>!?5#"?5##3|4>!2! crLY "(3?5505 49""9$494H""#"""""e5e5"("""5"""" n n4" Python Language Emacs Input/Output Redirection Functions Example 1: Create a directory BIO under your home directory. We will save all files in this directory. Type: mkdir BIO Change directory to your class directory, type the following on the Unix prompt: cd BIO Open a new file: emacs prog1.py & In the file prog1.py type the following program, including the comment lines #In this example function has one numeric parameter and function has a return value #function definition def circleArea (radius): area= radius *radius *3.14 return area # main function that uses the function welcome radius = 2.5 #function call inside print statement print circleArea ( radius ) print circleArea ( 3.5) radius = 4.5 #function call in assignment statement areaResult = circleArea ( radius ) print areaResult Save your program Go to the login window and type the following on the Unix prompt: chmod u+x prog1.py python prog1.py Observe the result Example 2: Open a new file: emacs prog2.py & In the file prog1.py type the following program, including the comment lines #In this example function has one numeric parameter, function doesnt have return value #function definition def mantra ( n ): counter =0 while counter < n: print I love Python counter = counter +1 #main program num = input (please enter the number ) print print the input value is , num #function call print the function result is print mantra (num) Save your program Go to the login window and type the following on the Unix prompt: chmod u+x prog2.py python prog1.py Enter the input number after user prompt Observe the result Create a new file that will include the data, do the following: Type on the Unix prompt: emacs data & In the file type: 7 Save the file and exit Go to the login window and type the following on the Unix prompt: python prog2.py < data Observe the result Go to the login window and type the following on the Unix prompt: python prog2.py < data > prog_result Open file with results by typing: emacs prog_result & Observe the results of the calculations Examples 3 and 4 provide more information about the functions in Python. Type each program in the separate file and run the program to observe the results. Example 3: #In this example function doesnt have any parameters, function doesnt has return value #function definition def fiveStars ( ): print ***** #main program num = input ( Please enter the number ) counter =0 while ( counter < num ): fiveStars ( ) counter = counter +1 Example 4: #function definition def scoreAlign (seq1, seq2): i=0 sum=0 length=len(seq1) while i* hu5$/:;GH / } ~   * + Z [ h  & Fgd\ & F$a$  - . @ 5 6 7    & FgdSK & FgdFi & FgdFi & Fgd   @ F g h w $M`K^# & FgdG_ & FgdSK & FgdSK4@K#$;<@׹ששעךzzvzvzzqlq hi_G\ hu\hu hu5 hu5>*hi_Ghi_G5hi_Ghi_G5CJaJhSKhu>* h?8huh?8h?8hu5CJaJh?85CJaJhA#khu5CJaJhA#k5CJaJ hSKhu hA#khu hA#khG_hG_hu5 hG_5 hA#kh9XO'#$&;<O^_mn ,:Sk#)@ov ,1h/ =!"#$% FzFE-Qڛb>"JFIFKKMSO Palette C   ")$+*($''-2@7-0=0''8L9=CEHIH+6OUNFT@GHEC !!E.'.EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"!!1AQqa!1 ?F3]'IƓe5,J$3?O 5LXyYL4tO%fxM\DXL`: a2HS=rtd+f\UtV5m7L?cf7 `Zx5\k@@@ NormalCJ_HaJmH sH tH DA@D Default Paragraph FontVi@V  Table Normal :V 44 la (k@(No List $  Z ? Iy /:;GH /}~*+Z[h-.@567@Fghw$M`K^#$& ; < O ^ _ m n  , : S k # ) @ o v e@e@$e@$e@$e@e@e@e@|e@|e@2e@2e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@$e@We@2e@2e@$e@e@e@$e@$e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@$e@$e@2e@2e@$e@$e@$e@e@e@$e@|e@$e@2e@|e@$e@e@2e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@e@/:;GH /}~*+Z[h-.@567@Fghw$M`K^#$& ; < O ^ _ m n  , : S k # ) @ o v 0 0 0 0000 0 0 0 0000000000000000000000 0 0 0@ 0@ 000 0 00000000000000000000000 0 0 0 0 0 0 0 0` 0` 0 0 0 0 0 000000000000000000000000000000000000000000/:;GH /}-.@5$M`K^#$ h00ظkh00h00h00h00h00h00h00h00h0 0 ,\!h0 0h0 0h0 0h0 0h00h00h00h00h00h00h00h00h00h00\z!h00h00h00h00h00h00h00h00h00h00h00h00h00h00h00h00h00h00h00h00h00h0-.S9h0-h0-h00h00h00h00X   #  l,R$FE-Qڛb>".$@0(  |  JA ?Parchment"  $   .op{jN'_i=|\@D2@-Y_!hh܏nh ^`OJQJo(h pp^p`OJQJo(oh @ @ ^@ `OJQJo(h ^`OJQJo(h ^`OJQJo(oh ^`OJQJo(h ^`OJQJo(h PP^P`OJQJo(oh   ^ `OJQJo(^`OJQJo(hH^`OJQJ^Jo(hHopp^p`OJQJo(hH@ @ ^@ `OJQJo(hH^`OJQJ^Jo(hHo^`OJQJo(hH^`OJQJo(hH^`OJQJ^Jo(hHoPP^P`OJQJo(hHh^`OJQJo(hHh^`OJQJ^Jo(hHohpp^p`OJQJo(hHh@ @ ^@ `OJQJo(hHh^`OJQJ^Jo(hHoh^`OJQJo(hHh^`OJQJo(hHh^`OJQJ^Jo(hHohPP^P`OJQJo(hHh^`OJQJo(hHh^`OJQJ^Jo(hHohpp^p`OJQJo(hHh@ @ ^@ `OJQJo(hHh^`OJQJ^Jo(hHoh^`OJQJo(hHh^`OJQJo(hHh^`OJQJ^Jo(hHohPP^P`OJQJo(hHh ^`OJQJo(h ^`OJQJo(oh pp^p`OJQJo(h @ @ ^@ `OJQJo(h ^`OJQJo(oh ^`OJQJo(h ^`OJQJo(h ^`OJQJo(oh PP^P`OJQJo(h^`OJQJo(hHh^`OJQJ^Jo(hHohpp^p`OJQJo(hHh@ @ ^@ `OJQJo(hHh^`OJQJ^Jo(hHoh^`OJQJo(hHh^`OJQJo(hHh^`OJQJ^Jo(hHohPP^P`OJQJo(hH-Y_.o\@Di=!hhN'                                                        ?8i_GSK9XOG_A#k!\ Fiu@ p A  @UnknownGz Times New Roman5Symbol3& z Arial?5 z Courier New;Wingdings"1hԒݒf   %4  2QLX ?u2CSCI 131  Python Language yanaWidener University$      Oh+'0 $0 P \ h tCSCI 131 Python Language yanaNormalWidener University13Microsoft Office Word@vA@`{B @xY@:Y ՜.+,0 hp  rutgers  CSCI 131 Python Language Title  !"#$%&'()*+,-./012356789:;=>?@ABCFRoot Entry F|LYH1Table :WordDocument*SummaryInformation(4DocumentSummaryInformation8<CompObjq  FMicrosoft Office Word Document MSWordDocWord.Document.89q