MATH 9 Study Guide - Final Guide: Binary Number, Gradient Descent, Polynomial

112 views9 pages
15 Oct 2018
School
Department
Course
Professor

Document Summary

When asked to write code, you should write working python code that has correct syntax. You should explain in 1-2 sentences what the idea for your solution is or write next to your code what it is doing. This will increase your chances of getting full/partial credit. Use the backs of the pages if needed. Practice final, page 2 of 9: (20 points) write down the output of the following programs, x = 1 s = 0 for i in range(8): s += x x += 1 print(s) Answer: this computes 1 + 2 + + 7 = 36: def f(n): if n > 0: return n * g(n) return 1 def g(n): return f(n // 2) print(f(6)) Answer: f (6) = 6 g(6), g(6) = f (3), f (3) = 3 g(3), g(3) = f (1), f (1) = 1 g(1), g(1) = f (0), f (0) = 1.