Setting up a subdirectory for week 4 in-class work
cd into your cs21/class/ subdirectory and create a new directory named 'week04',
then cd into that directory:
$ cd cs21/class # cd into your cs21/class subdirectory
$ mkdir week04 # make a subdirectory named week04
$ cd week04 # cd into it
Now copy over all the files from my public/cs21/week04 directory into your
week04 directory (remember to add the dot as the destination of the cp command).
From your week04 directory:
$ cp ~newhall/public/cs21/week04/* .
example_funcs.py infiniteloop.py squares.py syracuse.py
factorial.py randOps.py squares_list.py
format.py simple_while.py stars.py
Weekly In-class Examples
In Tuesday's class we are going to try out some programs with while
loops and learn the random library. We will look at some of the
- format.py: some examples of string formating for nicer ouput stmts
- simple_while.py: an example while loop
- infiniteloop.py: runs forever. stop it by type CNTL-C
- syracuse.py: try solving the syracuse sequence problem
- randomOps.py: examples using the randrange function from the random library
- stars.py: try solving some of these
In Thursday's class we are going to learn about functions. We will look
at some of the following:
- factorial.py: writing our own function
- squares.py: another example
- example_funcs.py: some different types of functions
- squares_list.py: a function with a list parameter
- create a new function in example_funcs.py named get_single_char
that prompts user to enter a single character and returns valid input to
the caller. It should not return until the user enters just a single character
input value. Replace a call to it in this function where it reads in the
- Does this function need any input values?
If so, how many? what type are they?
- Does this function return a value? If so, what type?
- Do we need a loop? for or while? What is condition?