# CS61A HOMEWORK 1

To test your solution, open an interactive interpreter python3 -i hw Pick a positive integer n as the start. Therefore, even if c returns False , the function t will be called. Fill in the blanks in the following function definition for adding a to the absolute value of b , without calling abs. Despite the doctests above, this function actually does not do the same thing as an if statement in all cases. 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. The max function can take an arbitrary number of arguments. The max function can take an arbitrary number of arguments. To test your solution, open an interactive interpreter python3 -i hw Write a function that takes three positive numbers and returns the sum of the squares of the two largest numbers. 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. If n is even, divide it by 2. Pick a positive integer n as the start. This is guaranteed to be the largest factor of n.

If n is even, divide it by 2. This is guaranteed to be the largest factor of n.

## CS61A Homework 1

This sequence of values of n is often called a Hailstone sequence, Write a function hoemwork takes a single argument with formal parameter name nprints out the hailstone sequence starting at nand returns the number of steps in the sequence:. 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. Analogously, a hailstone travels up and down in the atmosphere before eventually landing on earth. Use only a single line for the body of the function.

CURRICULUM VITAE MODEL ELEVI

If Function vs Statement Let’s write a function that does the same thing as hmoework if statement. The number n homeork 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.

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. Despite the doctests above, this function actually does not do the same thing as an if statement in all cases. 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.

If n is odd, multiply it by 3 and add 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. 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. We choose the operator add or sub based on the sign of b.

Therefore, even if c returns Falsethe function t will be called. 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. Iterating from n-1 to 1, we return the first integer that evenly divides n.

DISSERTATION SUR LA CHARTE CONSTITUTIONNELLE DE 1814

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: Use only a single line for the body of the function. Analogously, a hailstone travels up and down in the atmosphere before eventually landing on earth.

Continue this process until n is 1. Two of Three Write a function that takes three positive numbers and returns the sum of the squares of the two largest numbers.

So, we can take the max of the sum of squares of all pairs. Fill in the blanks in the following function definition for adding a to the absolute value of bwithout calling abs.

# Homework 1 Solutions | CS 61A Summer

Write a function that takes three positive numbers and returns the sum of the squares of the two largest numbers. The max function can take an arbitrary number of arguments.

Pick a positive integer n as the start. To test your solution, open an interactive interpreter python3 -i hw