### 2018-02-12 HW

posted Feb 11, 2018, 7:02 PM by Konstantinovich Samuel
 Goal: Generating a sequence with a loop.Notes on the print primitive:You can print with a comma at the end of the line to prevent the new line from printinge.g.print 5,    #the next print is on the same lineprint 6print 7outputs:5 67print 1print 2,    #the next print is on the same lineprint 3print 4outputs:12 34You can also separate values and print multiple things in one print statement:print 5, 6outputs:5 6print 5, 6print 7print 8,9outputs:5 678 9Classwork:The hailstone sequence starts at any natural number (positive integer), and always terminates with the value 1.To generate the sequence you follow a simple set of rules:if n = 1 : doneif n is even: the next number is n / 2if n is odd: the next number is 3 * n + 1So hailstone sequences starting with the first 6 values:n:  sequence1:  12:  2 1 3:  3 10 5 16 8 4 2 14:  4 2 15:  5 16 8 4 2 16:  6 3 10 5 16 8 4 2 1...1. Write a function printHail(n) that will print the hailstone sequence (on one line for readability)(Normally we don't print out things, instead we return them.  Since we know the starting/ending number of each sequence, it isn't a useful thing to return either. )Once you complete the function that prints the sequence, we can move on to returning something again. Something we cannot predict is the length of the sequence!2. Write a function that calculates the length of a hailstone sequence that starts with n: (look at the example sequences above to see why!) n ->  hailLen(n)1 -> 12 -> 23 -> 84 -> 35 -> 66 -> 9...Homework:Complete the hailstone problems on codingbat (under http://codingbat.com/home/konstans@stuy.edu/all  )