Difference between revisions of "CSC111 Lab 5 2018"
(3 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
---- | ---- | ||
− | + | <onlydft> | |
<br /> | <br /> | ||
<!--center><videoflash>tDhhDKjatLI</videoflash></center--> | <!--center><videoflash>tDhhDKjatLI</videoflash></center--> | ||
<br /> | <br /> | ||
− | + | ||
<bluebox> | <bluebox> | ||
This lab deals with functions, passing parameters, and returning values. It is also about for you to start the Python.org documentation on the Web. The online documentation is a great help when writing programs. The Moodle submissions are due on Friday 3/2/18 at 11:55 p.m. | This lab deals with functions, passing parameters, and returning values. It is also about for you to start the Python.org documentation on the Web. The online documentation is a great help when writing programs. The Moodle submissions are due on Friday 3/2/18 at 11:55 p.m. | ||
Line 444: | Line 444: | ||
3. Using this number, it gets the appropriate student name and prints out a new computer account with format First Initial Last Name | 3. Using this number, it gets the appropriate student name and prints out a new computer account with format First Initial Last Name | ||
ie. Sarah Brown turns into sbrown. | ie. Sarah Brown turns into sbrown. | ||
− | 4. | + | 4. Try to use functions if possible! |
Example Input/Output | Example Input/Output | ||
Line 455: | Line 455: | ||
4 Brown,Ben | 4 Brown,Ben | ||
5 Yang,Debbie | 5 Yang,Debbie | ||
− | Which student | + | Which student? 5 |
− | Debbie | + | Yang,Debbie dyang |
>>> | >>> | ||
+ | * Make sure you print a blank line before the result. The autograder needs this blank line to fully isolate the last line of your program. | ||
+ | <br /> | ||
==Moodle Submission== | ==Moodle Submission== | ||
<br /> | <br /> | ||
Line 465: | Line 467: | ||
<br /> | <br /> | ||
<br /> | <br /> | ||
− | </ | + | |
+ | </onlydft> | ||
<!-- =================================================================== --> | <!-- =================================================================== --> |
Latest revision as of 13:50, 1 June 2018
D. Thiebaut (talk) 05:52, 25 February 2018 (EST)
<showafterdate after="20180309 08:00" before="20180601 00:00">
Solution Programs
# --------------------- stickFigure ----------------------- def head(): print( " o" ) def leftArm(): print( " /", end="" ) def torso(): print( "O", end="" ) def rightArm(): print( "\\" ) def leftLeg(): print( " /", end="" ) def rightLeg(): print( " \\" ) def stickFigure(): head() leftArm() torso() rightArm() leftLeg() rightLeg() def body(): leftArm() torso() rightArm() def legs(): leftLeg() rightLeg() def newStickFigure(): head() body() legs() # --------------------- stickFigure1 ---------------------- def leftForearm1(): print( " /", end="" ) def sword1(): print( "+=====>" ) def leftArm1(): print( " \\", end="" ) def head1(): print( "O", end="" ) def rightArm1(): print( "___" ) def body1(): print( " |" ) print( " |" ) def leftThigh1(): print( " / ", end="" ) def rightThigh1(): print( "\\" ) def leftCalf1(): print( "/ ", end ="" ) def rightCalf1(): print( "\\" ) def stickFigure1(): leftForearm1() sword1() leftArm1() head1() rightArm1() body1() leftThigh1() rightThigh1() leftCalf1() rightCalf1() # ---------------------- Snow Man ---------------------- _ = """ __ _|==|_ ('')__/ >--(`^^`) (`^'^'`) `======' """ def hat2(): print(" __" ) print(" _|==|_" ) def headRightArm2(): print( " ('')__/" ) def leftArm2(): print( ">--", end="" ) def body2(): print( "(`^^`)" ) print(" (`^'^'`)" ) def base2(): print( " `======'" ) print() def snowMan(): hat2() headRightArm2() leftArm2() body2() base2() # --------------------------------------------------------- def happyBirthday(): print( "Happy birthday to you!" ) def happyBirthdayDear( name ): print( "Happy birthday, dear " + name +"!" ) def singSong( name ): happyBirthday() happyBirthday() happyBirthdayDear( name ) happyBirthday() def singHappy( ): # get the name from the user name = input( "Who's birthday should we celebrate? " ) # sing the song for that person singSong( name ) # ----------------- Another Version --------------------- def happyBirthday(): print( "Happy birthday to you!" ) def happyBirthdayDear( name ): print( "Happy birthday, dear " + name +"!" ) def singSong( name ): happyBirthday() happyBirthday() happyBirthdayDear( name ) happyBirthday() def singHappy2( ): # get a line of names, separated by spaces line = input( "Give me several names, please: " ) # remove extra spaces at the front or back line = line.strip() # split the line into individual names, and sing song for each for name in line.split( ): singSong( name ) # blank line separates the different songs print() def bar(): print( "\n" + ( "-"*30 ) + "oOo" + ("-"*30 ) +"\n" ) def identifyDNA( DNA ): return DNA.replace( "AGA", "###" ) def trimDNA( DNA ): marker = "AGA" index1 = DNA.find( marker ) index2 = DNA.find( marker, index1+1 ) return DNA[index1:index2 + len( marker )] def DNAProblem(): DNA = "AAGACTAAAAAAGACTT" #input( "Enter DNA: " ) print( "DNA =", DNA ) # show where the markers are newDNA = identifyDNA( DNA ) print( newDNA ) # remove symbols on each side of the markers newDNA = trimDNA( DNA ) print( newDNA ) def challenge4(): sentence = "the quick red fox jumped" # input( "Sentence? " ) print( "Sentence =", sentence ) sum = 0 words = sentence.split() for word in words: sum = sum + len( word ) print( "average word length = {0:1.2f}".format( sum/len(words) ) ) def challenge5(): students = ["Brown,Sarah", "McCharles,Charlie", "Hudson,Stanley", "Smith,Margaret", "Brown,Ben", "Yang,Debbie"] # display the students for i in range( len( students ) ): print( i, students[i] ) # get index from user index = 3 # input( "Which student? " ) name = students[index] last, first = name.split( ',' ) account = first[0] + last account = account.lower() print( name, account ) def main(): newStickFigure() stickFigure1() snowMan() singHappy() singHappy2() DNAProblem() challenge4() challenge5() main()
</showafterdate>