Difference between revisions of "CSC231 Final Exam Fall 2017"

From dftwiki3
Jump to: navigation, search
Line 75: Line 75:
 
  fact( 6 ) = 208
 
  fact( 6 ) = 208
 
  fact( 10 ) = 0
 
  fact( 10 ) = 0
 
 
<br />
 
<br />
 +
==Question ==
 
<br />
 
<br />
* For reference, here is a python version of what you have to do:
+
In the header of your program, explain the program returns 0 for fact(10).  If you are not sure, suggest the most likely reason.
 
<br />
 
<br />
::<source lang="python">
+
==Submission==
#! /usr/bin/env python3
 
# factorial.py
 
# D. Thiebaut
 
from __future__ import print_function
 
import sys
 
 
 
def fact( n ):
 
    if n==1:
 
        return 1
 
    res = fact( n-1 )
 
    return n * res
 
 
 
if len( sys.argv ) != 2:
 
    print( "Syntax: ./factorial.py nnnn" )
 
    print( "where nnnn is a positive integer" )
 
    sys.exit()
 
 
 
n = int( sys.argv[1] )
 
print( "fact(", n, ") =", fact( n ) )
 
</source>
 
 
<br />
 
<br />
 +
Submit your program in the Problem 3 section on Moodle.
 
<br />
 
<br />
 +
 
=Solutions=
 
=Solutions=
 
==Bash Script==
 
==Bash Script==

Revision as of 20:45, 10 December 2017


...