Starting from:

$25

CS61A- Homework 1: Control Solved

Download hw01.zip (hw01.zip).

Submission: When you are done, submit with  python3 ok --submit . You may submit more  than once before the deadline; only the final submission Il be scored. Check that you have successfully submitted your code on okpy.org (https://okpyorg/ . ee Lab O (/lab/labOO#submitting-the-assignment) for more instructions on submitting assignments. using Ok: If you have any questions about using Ok, please refer to this guide.

(/articles/using-ok)

Readings: You might find the following references useful:

Section 1.1 (http://composingprograms.com/pages/ll-getting-started.html)

Section 1.2 (http://composingprograms.com/pages/12-elements-of-programming.html)

Section 1.3 (http://composingprograms.com/pages/13-defining-new-functions.html)

Section 1.4 (http://composingprograms.com/pages/14-designing-functions.html)

Section 1.5 (http://composingprograms.com/pages/15-control.html)

ill cover readings 1.3-1.5, which contain the

radin

raded based

ectness. Each incorrect problem will decrease v pdefslargest—factorthe Syllabus Quiz (https://go.cs61a.org/syllabus-quiz), which is based of our policies found on the course syllabus (https://cs61a.org/articles/about/), as well as the

optional Welcome def invert adding a to the absolute value Of b , without. I Provided code other than the two blanks.

4

retur

räfurn

D i ilar structure. In both,

prevents a

int:

can be

squares

return

Consider

max( ,

even divides

, you can

remainder Of dividing a by

code

he expression

is O."

which

three positive numbers as arguments and returns the sum of the

sma est numbers. Use only a single line for the body of the function.

the

function:

max or min

integer

that is greater than 1 and returns the largest intege uares

return

Consider

max(

min(

if

return

else

return

three positive numbers as arguments and returns the sum of the smallest numbers. Use only a single line for the body of the function.

the

function:

max or min

integer

that is greater than 1 and returns the largest intege

evenly divides

code

if

return

else

limit

return

"refactor" a program means to rewrite it

ange to the design. Below is an attempt to finitions by defining a new function limited C return 2f change_short that it has the same behavior but with some factor both functions to have short one-line that contains their common structure. def hailstone

Our first job is to understand why the behavior changed. In

division by x only

invert ,

appens when x is not O, but in

it always happens. Read the rules Of

invert_short

valuation for if Statements (http://composingprograms.com/pages/15-

ontrol.html#conditional-statements) and call expressions

0 see why.

our second job is to edit

and

so that they have the same

invert _ short

change_short

ehavior as

and

but still have just one line each. You will also need to edit

i nvert

change

Limited . You don't need to use

and

livision takes place.

in invert ; just pay attention to when the

if Ise Ok to es code: nces can *uite long! Try 27 What's the longest you can tindQ

sec

U 0k

your code:

Dgyglas Her Pulitzer-prize-winning book, Gödel, Escher, Bach, poses the following hailstones or hailstone sequences? Take a 100k at these articles:

out this to learn

2. work!

4.
conjecture-20191211/) in understanding how the hailstone conjecture works for most. They 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).

Analogously, a hailstone travels up and down in the atmosphere before eventually landing on, This question is out Of scope for 61A. You can try it if you want an extra challenge, but it's just a puzzle that has no practical value and is not required or recommended at all. Almost all students will skip it, and that's fine.

Write a one-line program that prints itself, using only the following features Of the python

language:

Number literal

• Assignment statements

• String literals ha can be expressed using single or double quotes

The arithmetic operators

* , and Y can concatena wo s

b

by

er. emico

adding them together with • and repeat a string by can be used to separate multiple statements on the

t:

func

xplore the relationship between single quotes, double quotes, and the

repr

applied to strings.

A

ram

named

at

est

t t If is called a Quine. Place your solution in the multi-line string

cod f

More products