If n is even, divide it by 2. Use only a single line for the body of the function. This sequence of values of n is often called a Hailstone sequence, Write a function that takes a single argument with formal parameter name n, prints out the hailstone sequence starting at n, and returns the number of steps in the sequence: If you are having a hard time identifying how the if statement and if function differ, first try to get them to print out different values. Use only a single line for the body of the function. Fill in the blanks in the following function definition for adding a to the absolute value of b , without calling abs. Two of Three Write a function that takes three positive numbers and returns the sum of the squares of the two largest numbers.

If Function vs Statement Let’s write a function that does the same thing as an if statement. The max function can take an arbitrary number of arguments. Pick a positive integer n as the start. This sequence of values of n is often called a Hailstone sequence, Write a function that takes a single argument with formal parameter name n , prints out the hailstone sequence starting at n , and returns the number of steps in the sequence:. Write a function that takes three positive numbers and returns the sum of the squares of the two largest numbers. Use only a single line for the body of the function.

Fill in the blanks in the following function definition for adding a to the absolute value of bwithout calling abs.

## CS61A Homework 1

If n is odd, multiply it by 3 and add 1. To test your solution, open an interactive interpreter python3 -i hw So, we can take the max of the sum of squares of all pairs. Continue this process until n is 1.

The number n will travel up and down but eventually end at 1 at least for all numbers that have ever been tried — nobody has ever proved that the sequence will terminate. Write a function that takes an integer homewofk that is greater than 1 and returns the largest integer that is smaller than n and evenly divides n. This sequence of values of n is often called a Hailstone sequence, Write a function that takes a single argument with formal parameter name n, prints out the hailstone sequence starting at n, and returns the number of steps in the sequence: This sequence of values of n is often called a Hailstone sequence, Write a function that takes a single argument with formal parameter name nprints out the hailstone sequence starting at nand returns the number of steps in the sequence:.

A Plus Abs B Fill in the blanks in the following function definition for adding a to the absolute value of b, without calling abs. We choose the operator add or sub based on the sign of b. Despite the doctests above, this function actually cs6a not do the same thing as an if statement in all cases. The number n will travel up and down but eventually end at 1 at least for all numbers c61a have ever been tried — nobody has ever proved that the sequence will terminate.

Use only a single line for the body of the function. Use only a single line for the body of the function. If n is even, homeworl it by 2. Write a function that takes three positive numbers and returns the sum of the squares of the two largest numbers. If you are having a hard time identifying how the if cs16a and if function differ, first try to get them to print out different values.

# Homework 1 Solutions | CS 61A Summer

This is guaranteed to be the largest factor of n. Therefore, even if c returns Falsethe function t will be called.

Analogously, a hailstone travels up and down in the atmosphere before eventually landing on earth. If you are having a hard time identifying how the if statement and if function differ, first try to get them to print out different values.

Pick a positive integer n as the start. Largest Factor Write a function that takes an integer n that is greater than 1 and returns the largest integer that is smaller than n and evenly divides n. Two of Three Write a function that takes three positive numbers and returns the sum of the squares of the two largest numbers. Iterating from n-1 to 1, we return the first integer that evenly divides n.

If Function vs Statement Let’s write a function that does the same thing as an if statement.

Analogously, a hailstone travels up and down in the atmosphere before eventually landing on earth. The max function can take an arbitrary number of arguments.