cs102 lab3
http://www.maths.nuigalway.ie/~gettrick/teach/cs102/labs/l3.html
-
For this lab you must submit all source code (python
files), and, if applicable, the result(s) of running the program on (a few)
test cases. This should be sent in via BLACKBOARD (not directly by email).
The source code must
be well presented (indenting, spaces, reasonable variable/function names,
etc.) and must include comments (as a rough guideline - aim to have nearly as
many comments as lines of code). Any questions asked should be answered by
typing into a plain text (.txt) file which should also
be uploaded via blackboard.
-
This material should be uploaded
before
the deadline of 5pm
Friday February 11th, 2011. You will lose 20% for each day
(or part of day) the lab is late.
-
Plagiarism (the unattributed copying of work from other sources
(internet, fellow students,....)) will not be tolerated. Please see
http://www.nuigalway.ie/engineering/documents/plagiarism_guide_students
_v4.pdf. You risk getting zero for your lab if it is found to be
plagiarized.
This week, you are asked to write solutions in PYTHON using
recursive functions.
-
Write a program in PYTHON to calculate the
double factorial of a Natural Number
input by the user. The
double factorial
of n (written as n!!) is n(n-2)(n-4)...
so for example 7!! = (7)(5)(3)(1) = 105 while 6!! = (6)(4)(2) = 48.
Your program must use a recursive function.
(Be careful of the
two different base cases for n even or odd).
-
For a certain application, the user must choose a password that has
no vowels. Write a program that reads in from the user
(use raw_input) a possible password, and checks that it matches
this requirement. You must use a recursive function.
(Hint:
Your function can take as input a string. Then it checks the first letter.
If that letter is not a vowel, let the function call itself, with as
input the string minus the first letter (use a slice!). If
the first letter is a vowel,
return some constant from the function (e.g. 1). If the input string
to the function is NULL, return some other constant (e.g. 0). Then in
your main program, use the returned value to print out something
meaningful to the user.)
©
NUI, Galway