- Before proceeding - read this entire document (
*and*the entire stub file)*thoroughly*! - Work on your own.
- Unless otherwise indicated, use only the Python operations and commands we have described thus far in class.
- Start by working with the supplied starter file, but save the file as
`hw1_`where*yourusername*.py*yourusername*is your`@gm.slc.edu`username. - Replace
with*your name*. - Your written (i.e. non-programming) answers must be in the form of comments so that your entire file can load correctly using Spyder.
- Fill in all the areas of the supplied file marked by "...".
- As mentioned above, name your file
`hw1_`where*yourusername*.py*yourusername*is your`@gm.slc.edu`username. (If your email was`msiff@gm.slc.edu`, you would name your file`hw1_msiff.py`.)

- When ready to submit your work,
**reply to the email officially announcing the assignment**and*attach*the one file. (Do not paste the contents of the file into the body of the message. Do not expect the instructor to read anything in the body of the message. The instructor will only examine the attached file.)

Complete the function

`tri_num(m)`

so that it returns half of the product of`m`

and one more than`m`

. Examples:`In []: tri_num(0) Out []: 0 In []: tri_num(3) Out []: 6 In []: tri_num(6) Out []: 21`

Complete

`zero_off(n)`

so that it returns the string`'off'`

if`n`

is zero and`'on'`

if`n`

is nonzero. Examples:`In []: zero_off(0) Out []: 'off' In []: zero_off(4103) Out []: 'on'`

Complete

`pad_bang(s, n)`

so that it returns a new string of (at least) length`n`

that is the same as`s`

but with as many`'!'`

characters appended as necessary to make the length at least`n`

. Examples:`In []: pad_bang('hi', 2) Out []: 'hi' In []: pad_bang('bye', 2) Out []: 'bye' In []: pad_bang('cool', 9) Out []: 'cool!!!!!'`

Complete

`append_digit(n, d)`

so that it returns an integer that is like`n`

but with digit`d`

appended at its end. Assume`d`

is a nonnegative integer less than 10; otherwise it should just return`n`

. Examples:`In []: append_digit(410, 3) Out []: 4103 In []: append_digit(61, 0) Out []: 610 In []: append_digit(32767, 49) Out []: 32767`

Complete

`pow5(n)`

so that it returns 5 raised to the`n`

power. Use a`while`

loop; do*not*use the exponentiation operator (`**`

). Examples:`In []: pow5(0) Out []: 1 In []: pow5(2) Out []: 25 In []: pow5(4) Out []: 625 In []: pow5(37) Out []: 72759576141834259033203125`

Complete

`sum_digits(n)`

so that it returns the sum of the digits in`n`

. Examples:`In []: sum_digits(0) Out []: 0 In []: sum_digits(41) Out []: 5 In []: sum_digits(9876) Out []: 30`

Complete

`unary_digits(n)`

so that it returns a string representation of`n`

where each digit of`n`

is expressed in*unary*- i.e., as the corresponding number of`'*'`

characters repeated. Digit places should be separated by the`'|'`

character.*You are encouraged to take advantage of Python's string multiplication operator (*. Examples:`*`

)`In []: unary_digits(0) Out []: '' In []: unary_digits(7) Out []: '*******' In []: unary_digits(4103) Out []: '****|*||***'`

Complete

`collatz_count(m)`

so that it returns the number of iterations of the Collatz (Ulam) calculation required to get from`m`

down to 1. For example, to go from 3 requires 7 steps:`3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1`

Assume

`m`

is positive. Examples:`In []: collatz_count(1) Out []: 0 In []: collatz_count(4) Out []: 2 In []: collatz_count(3) Out []: 7`

Complete

`threes(m)`

so that it returns the number of times that`m`

can be repeatedly divided by 3. Assume`m`

is positive. Examples:`In []: threes(3) Out []: 1 In []: threes(7) Out []: 0 In []: threes(45) Out []: 2 In []: threes(1134) Out []: 4`

Complete

`count_primes(n)`

so that it returns the number of prime numbers less than or equal to`n`

. Examples:`In []: count_primes(2) Out []: 1 In []: count_primes(10) Out []: 4 In []: count_primes(100) Out []: 25`