cs102 lab3


http://www.maths.nuigalway.ie/~gettrick/teach/cs102/labs/l3.html




This week, you are asked to write solutions in PYTHON using recursive functions.

  1. 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).
  2. 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