Difference between revisions of "CSC111 Lab 6 2015b"
Line 67: | Line 67: | ||
− | Problem # | + | Problem #4: |
========== | ========== | ||
Line 96: | Line 96: | ||
<code><pre> | <code><pre> | ||
− | + | Problem #5: | |
− | |||
− | |||
− | Problem # | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
========== | ========== | ||
Line 125: | Line 105: | ||
6 characters wider than the name of the user. | 6 characters wider than the name of the user. | ||
− | Here's an example | + | Here's an example output: |
Line 133: | Line 113: | ||
</pre></code> | </pre></code> | ||
<br /> | <br /> | ||
− | <source lang="text"> | + | ::<source lang="text"> |
***************** | ***************** | ||
* * | * * | ||
Line 149: | Line 129: | ||
</pre></code> | </pre></code> | ||
− | <source lang="text"> | + | ::<source lang="text"> |
************************************ | ************************************ | ||
* * | * * | ||
Line 156: | Line 136: | ||
************************************ | ************************************ | ||
</source> | </source> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
<br /> | <br /> | ||
</showafterdate> | </showafterdate> |
Revision as of 16:26, 12 October 2015
--D. Thiebaut (talk) 17:20, 12 October 2015 (EDT)
The lab is an exploration of various questions and concepts dealing with Python, and is a preparation for Friday's midterm exam. The questions will be given out in class, and explored on the whiteboard.
<showafterdate after="20151014 12:10" before="20151231 00:00">
Problem #1:
==========
What is the output of the following python program?
a = 3
b = 4
for a in range( b ):
print( a, a+b )
Problem #2:
==========
What is the output of the following program?
(tricky)
print( "you win: " )
for i in range( -3, 0, -1 ):
print( "hip,", sep='-' )
print( "hourrah!" )
Problem #3:
==========
Write the code necessary to print the first, third, fifth, seventh,... words
of the following list of words.
L = [ "the", "quick", "red", "fox", 'jumped', 'over',
'the', 'lazy', 'brown', 'sleeping', 'dog' ]
In other words, the output for this list of words should be:
the red jumped the brown dog
Make sure your code works with any list of words, not just the one given here.
In particular, you shouldn't use the number 11, which is the number of words
in the list.
Problem #4:
==========
When we run the program below, it outputs 18 10.
What were the 2 numbers entered by the user?
def f1( a ):
b = 5
return a*2
def f2( b ):
a = 3
return b+a
def main():
a = input( "Enter first number? " )
b = input( "Enter second number? " )
print( f1( b ), f2( a ) )
main()
Problem #5:
==========
Write a python program (you do not need to use functions, but you can if
you prefer) that asks the user for her full name (first and last name),
and outputs the name on the screen with a box of stars around it, such
that the user's name is centered in the box. The box should be exactly
6 characters wider than the name of the user.
Here's an example output:
python problem8.py
What is your name? Alan Turing
***************** * * * Alan Turing * * * *****************
Here is another example:
python problem8.py
What is your name? Nabucodonosor, King of Babylon
************************************ * * * Nabucodonosor, King of Babylon * * * ************************************
</showafterdate>