Difference between revisions of "CSC111 Games around Functions"

From dftwiki3
Jump to: navigation, search
(Game 4)
(Game 5)
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
--[[User:Thiebaut|D. Thiebaut]] 09:47, 20 October 2011 (EDT)
 
--[[User:Thiebaut|D. Thiebaut]] 09:47, 20 October 2011 (EDT)
 
----
 
----
 
+
<br />
 +
__TOC__
 +
<br />
 +
<bluebox>
 +
Each game below can be played in class just to get the idea of what goes on.  Think of the game as a play.  Students are actors and have lines to say.  When the director points to an actor, the actor says her line.  Once a game is played in class and fully understood, translate it into python, using '''functions'''.
 +
</bluebox>
 +
<br />
 
=Game 1=
 
=Game 1=
 
+
<br />
 
* Student 1
 
* Student 1
 
** Say "Banana!"
 
** Say "Banana!"
Line 18: Line 24:
 
** Call Student3
 
** Call Student3
  
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 
=Game 2=
 
=Game 2=
 
+
<br />
* Student 1
+
<br />* Student 1
 
** Say "Banana!"
 
** Say "Banana!"
  
Line 35: Line 46:
 
** repeat 2 times:
 
** repeat 2 times:
 
*** Call Student3
 
*** Call Student3
 
+
<br />
 
+
<br />
 +
<br />
 +
<br />
 +
<br />
 
=Game 3=
 
=Game 3=
 
+
<br />
 
* Student 1
 
* Student 1
 
** Say "Caramba!"
 
** Say "Caramba!"
Line 53: Line 67:
 
** Call Student 1
 
** Call Student 1
 
** Call Student 3
 
** Call Student 3
 
+
<br />
 +
<br />
 +
<br />
 +
<br />
 
=Game 4=
 
=Game 4=
 
+
<br />
 
* Student 1 ( sentence )
 
* Student 1 ( sentence )
 
** Get sentence
 
** Get sentence
Line 73: Line 90:
 
** Call Student 1 and pass "I am tired"
 
** Call Student 1 and pass "I am tired"
 
** Call Student 2 and pass "I live for Chocolate"
 
** Call Student 2 and pass "I live for Chocolate"
** Call Student 3 and pass "We have no labs on November 10!"  
+
** Call Student 3 and pass "Almost Spring Break!"  
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
  
 +
=Game 5=
 
<br />
 
<br />
 +
* Student 1 ( sentence1, sentence2 )
 +
** Get sentence1 and sentence2
 +
** ask Student2 to say sentence1
 +
** ask Student3 to say sentence2
 +
 +
* Student 2 (sentence )
 +
** get sentence
 +
** Say "Hear this:" and then say sentence
 +
 +
* Student 3 (sentence )
 +
** get sentence
 +
** Say "The news is: " and then say sentence
 +
 +
* main
 +
** Call Student 1 and pass "Spring Break in two weeks!", and "Exam in a week and a half"
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<onlydft>
 +
=Solution Code=
 +
<source lang="python">
 +
# playingWithFunctions.py
 +
# D. Thiebaut  CSC111
 +
#
 +
 +
#--- first set of exercises ---
 +
"""
 +
def hello():
 +
    print( "hello" )
 +
 +
def helloBox():
 +
    print( "+-----+" )
 +
    print( "|hello|" )
 +
    print( "+-----+" )
 +
    print()
 +
   
 +
hello()
 +
helloBox()
 +
for i in range( 3 ):
 +
    helloBox()
 +
"""
 +
 +
#--- Game 1 implementation ---
 +
def student1():
 +
    print( "Banana!" )
 +
 +
def student2():
 +
    print( "Orange!" )
 +
 +
def student3():
 +
    print( "Peanut Butter!" )
 +
 +
"""
 +
student1()
 +
student2()
 +
student3()
 +
"""
 +
 +
#--- Game 2 implementation ---
 +
"""
 +
for i in range( 3 ):
 +
    student1()
 +
   
 +
student2()
 +
 +
for i in range( 2 ):
 +
    student3()
 +
"""
 +
 +
#--- Game 3 implementation ---
 +
def student3Game3():
 +
    student1()
 +
    print( "Si!" )
 +
"""
 +
student2()
 +
student1()
 +
student3Game3()
 +
"""
 +
 +
#--- Game 4 implementation ---
 +
def student1Game4( sentence ):
 +
    print( sentence )
 +
 +
def student2Game4( sentence ):
 +
    print( "My T-shirt says", sentence )
 +
 +
def student3Game4( sentence ):
 +
    print( "And now listen to this:", sentence )
 +
 +
student1Game4( "I am tired" )
 +
student2Game4( "I live for chocolate!" )
 +
student3Game4( "Almost Spring Break!" )
 +
 +
#--- Game 5 implementation ---
 +
def student1Game5( sentence1, sentence2 ):
 +
    student2Game5( sentence1 )
 +
    student3Game5( sentence2 )
 +
 +
def student2Game5( sentence ):
 +
    print( "Hear this:", sentence )
 +
 +
def student3Game5( sentence ):
 +
    print( "The news is:", sentence )
 +
 +
string1 = "Spring break in two weeks"
 +
string2 = "Exam in a week and a half"
 +
student1Game5( string1, string2 )
 +
 +
 +
</source>
 +
</onlydft>
 
<br />
 
<br />
 
[[Category:CSC111]][[Category:Python]][[Category:Exercises]]
 
[[Category:CSC111]][[Category:Python]][[Category:Exercises]]

Latest revision as of 10:00, 3 March 2014

--D. Thiebaut 09:47, 20 October 2011 (EDT)




Each game below can be played in class just to get the idea of what goes on. Think of the game as a play. Students are actors and have lines to say. When the director points to an actor, the actor says her line. Once a game is played in class and fully understood, translate it into python, using functions.


Game 1


  • Student 1
    • Say "Banana!"
  • Student 2
    • Say "Orange!"
  • Student 3
    • Say "Peanut Butter!"
  • Main
    • Call Student1
    • Call Student2
    • Call Student3






Game 2



* Student 1

    • Say "Banana!"
  • Student 2
    • Say "Orange!"
  • Student 3
    • Say "Peanut Butter!"
  • Main
    • repeat 3 times:
      • Call Student1
    • Call Student2
    • repeat 2 times:
      • Call Student3






Game 3


  • Student 1
    • Say "Caramba!"
  • Student 2
    • Say "No, No, No!"
  • Student 3
    • Call Student 1
    • Say "Si!"
  • Main
    • Call Student 2
    • Call Student 1
    • Call Student 3





Game 4


  • Student 1 ( sentence )
    • Get sentence
    • Say the sentence
  • Student 2 ( sentence )
    • Get sentence
    • Say "My T-Shirt says: "
    • Say the sentence
  • Student 3 ( sentence )
    • Get sentence
    • Say "And now listen to this: "
    • Call student 1 and pass her sentence
  • Main
    • Call Student 1 and pass "I am tired"
    • Call Student 2 and pass "I live for Chocolate"
    • Call Student 3 and pass "Almost Spring Break!"






Game 5


  • Student 1 ( sentence1, sentence2 )
    • Get sentence1 and sentence2
    • ask Student2 to say sentence1
    • ask Student3 to say sentence2
  • Student 2 (sentence )
    • get sentence
    • Say "Hear this:" and then say sentence
  • Student 3 (sentence )
    • get sentence
    • Say "The news is: " and then say sentence
  • main
    • Call Student 1 and pass "Spring Break in two weeks!", and "Exam in a week and a half"
















...