Difference between revisions of "CSC111 Mid-Semester Review 2018"
(→Strings) |
(→Range) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
[[Image:TheAnswerPad.png|right|150px]] | [[Image:TheAnswerPad.png|right|150px]] | ||
* We'll use a clicker (The Answer-Pad) during this review. Go to [http://app.theanswerpad.com/student#interactive http://app.theanswerpad.com/student] to answer various questions. | * We'll use a clicker (The Answer-Pad) during this review. Go to [http://app.theanswerpad.com/student#interactive http://app.theanswerpad.com/student] to answer various questions. | ||
+ | |||
+ | =Format= | ||
+ | |||
+ | * What is printed by this statement? | ||
+ | |||
+ | print( "({0:3}) {1:3}-{2:4}".format( "413", "584", "3854" ) ) | ||
+ | |||
+ | * What is output by this statement? | ||
+ | |||
+ | print( "({0:1}) {1:1}-{2:1}".format( "413", "584", "3854" ) ) | ||
+ | |||
+ | * What is output by this statement? | ||
+ | |||
+ | print( "({1:3}) {0:3}-{2:4}".format( "413", "584", "3854" ) ) | ||
+ | |||
=Range= | =Range= | ||
Line 45: | Line 60: | ||
=Functions= | =Functions= | ||
+ | |||
+ | * Is this function valid (i.e. Python will not report an error if it finds it in our program)? | ||
+ | ::<source lang="python"> | ||
+ | def doNothing( a ): | ||
+ | return 1 | ||
+ | </source> | ||
+ | * What is <tt>None</tt>? | ||
+ | * Is this function valid? | ||
+ | ::<source lang="python"> | ||
+ | def doNothing2( a ): | ||
+ | return | ||
+ | </source> | ||
+ | * The output of this program is 7. What did the user enter? | ||
+ | ::<source lang="python"> | ||
+ | def f1( a, b ): | ||
+ | return a - b | ||
+ | |||
+ | x = eval( input( "> " ) ) | ||
+ | print( f1( x, 3 ) ) | ||
+ | </source> | ||
+ | * The output of this program is 5. What did the user enter? | ||
+ | ::<source lang="python"> | ||
+ | def f2( y, x ): | ||
+ | return y - x | ||
+ | |||
+ | x = eval( input( "> " ) ) | ||
+ | y = 10 | ||
+ | print( f2( x, y ) ) | ||
+ | </source> | ||
+ | * What is printed by the program? | ||
+ | ::<source lang="python"> | ||
+ | def f2( y, x ): | ||
+ | z = 4 | ||
+ | return y - x | ||
+ | |||
+ | print( f2( 5, 3 ) ) | ||
+ | print( z ) | ||
+ | </source> |
Latest revision as of 20:33, 4 March 2018
D. Thiebaut (talk) 19:17, 4 March 2018 (EST)
Contents
Preparation
- We'll use a clicker (The Answer-Pad) during this review. Go to http://app.theanswerpad.com/student to answer various questions.
Format
- What is printed by this statement?
print( "({0:3}) {1:3}-{2:4}".format( "413", "584", "3854" ) )
- What is output by this statement?
print( "({0:1}) {1:1}-{2:1}".format( "413", "584", "3854" ) )
- What is output by this statement?
print( "({1:3}) {0:3}-{2:4}".format( "413", "584", "3854" ) )
Range
- Is range a function?
- How many parameters does it take?
- What are they?
- Can range crash if we give it incompatible parameters?
- Can its parameters be variables? i.e. range( a, b, c)?
- When is range() useful?
Lists
- How are lists defined?
- What different symbols are used to define lists?
- Can we mix the symbols to open and close the list?
- Can lists be empty? If so, give examples of empty lists.
- Can list elements be of different types? Can a list element be another list?
- Can list grow? How?
- How can we replace the first element of a non-empty list with a different value?
- How can we remove the first element of a non-empty list?
- How can we remove the last element of a non-empty list?
- How can we create a list that is the concatenation of two lists?
Strings
- Are strings mutable?
- is
a = ""
- a valid string?
- How can we remove the first letter of a non-empty string?
- How can we remove the last letter of a non-empty string?
- How can we create the reverse of a string ("hello" --> "olleh")
- How do we go from "The quick red fox" to [ "The", "quick", "red", "fox"]?
- How do we go from " The quick red fox " to [ "The", "quick", "red", "fox"]?
- How do we print the first word of a sentence, i.e. extract "Viva" from the string "Viva Fresh Pasta"?
- Give the name of 5 string methods
Functions
- Is this function valid (i.e. Python will not report an error if it finds it in our program)?
def doNothing( a ): return 1
- What is None?
- Is this function valid?
def doNothing2( a ): return
- The output of this program is 7. What did the user enter?
def f1( a, b ): return a - b x = eval( input( "> " ) ) print( f1( x, 3 ) )
- The output of this program is 5. What did the user enter?
def f2( y, x ): return y - x x = eval( input( "> " ) ) y = 10 print( f2( x, y ) )
- What is printed by the program?
def f2( y, x ): z = 4 return y - x print( f2( 5, 3 ) ) print( z )