E19 HW 1 Hints
Problem 1
Part (a):
You might want to start by making an analogy with decimal numbers. For example, the (decimal) number 3975 can be 'decoded' in the following way:
3975 divided by 10 gives 397 as the quotient and 5 as the remainder
397 divided by 10 gives 39 as the quotient and 7 as the remainder
39 divided by 10 gives 3 as the quotient and 9 as the remainder
3 divided by 10 gives 0 as the quotient and 3 as the remainder
This gives us 3, 9, 7 and 5 as the four digits of this number.
Problem 2
You will need to write a function that 'returns' a value. The basic structure of a Python function is like this:
def func(a,b): # a and b are the input arguments. c = 2*a + b # do something to the input arguments and assign to a new variable c return cAfter you write a function like this and run it in Python, that instance of Python will 'remember' the function and you will be able to execute the following code:
func(4,5)To write the function needed in this part, you will need a function that has a 'for loop' inside it, which successively adds the necessary terms.
You will also likely need to use the 'factorial' function, which in Python is hidden away in the 'math' package, which you will have to import.
def exponent_function(x,n): sum = 1 for j in range(1,n+1): sum = sum + () # you need to put something in hereSee the 'Using Packages' section of the Installation, Virtual Environments and Packages guide to look at different ways of importing the 'factorial' function from the math package. On way would be:
import mathmath.factorial(6)