cs107-lecture-examples

Example codes used during Harvard CS107 lectures
git clone https://git.0xfab.ch/cs107-lecture-examples.git
Log | Files | Refs | README | LICENSE

factorial.py (202B)


      1 #!/usr/bin/env python3
      2 
      3 
      4 def factorial(x):
      5     if x > 1:
      6         return x * factorial(x - 1)  # recursive call
      7     return 1
      8 
      9 
     10 def main():
     11     return factorial(5)
     12 
     13 
     14 if __name__ == "__main__":
     15     main()