text: Lab 1: Variables & Functions, Control
  Due by 11:59pm on Friday, June 25.
  Starter Files
  Download lab01.zip. Inside the archive, you will find starter files for the questions in this lab, along with a copy of the Ok autograder.
  Additionally, please fill out this survey with any issues you might have faced in Lab 0 Python installation or if you used the Windows automated installer.
  For quickly generating ok commands, you can now use the ok command generator.
  Quick Logistics Review foo foo foo.py
  Using OK
  In 61A, we use a program called Ok for autograding labs, homeworks, and projects. You should have Ok in the starter files downloaded at the start of this lab. For more information on using Ok commands, learn more here.
  You can quickly generate most ok commands at links.cs61a.org/ok-help!
  You can also use the debug printing feature in OK by writing
  print("DEBUG:", x)
  Finally, when you have finished all the questions in
  lab01.py, you must submit the assignment using the
  --submit option:
  python3 ok --submit
  Pair programming
  This lab is a really great chance to start trying out pair programming! You can visit this page for a refresher on how :)
  Topics
  Consult this section if you need a refresher on the material for this lab. It's okay to skip directly to the questions and refer back here should you get stuck.
  Division, Floor Div, and Modulo
  Let's compare the different division-related operators in Python 3:
  Functions
  If we want to execute a series of statements over and over, we can abstract them away into a function to avoid repeating code.
  For example, let's say we want to know the results of multiplying the numbers 1-3 by 3 and then adding 2 to it. Here's one way to do it:
  >>> 1 * 3 + 2 5 >>> 2 * 3 + 2 8 >>> 3 * 3 + 2 11
  If we wanted to do this with a larger set of numbers, that'd be a lot of repeated code! Let's write a function to capture this operation given any input number.
  def foo(x): return x * 3 + 2
  This function, called
  foo, takes in a single argument and will return the
  result of multiplying that argument by 3 and adding 2.
  Now we can call this function whenever we want this operation to be done:
  >>> foo(1) 5 >>> foo(2) 8 >>> foo(1000) 3002
  Applying a function to some arguments is done with a call expression.
  Call expressions:
  - Evaluate the operator, and then the operands (from left to right).
  - Apply the operator to the operands (the values of the operands).
  If an operand is a nested call expression, then these two steps are applied to that inner operand first in order to evaluate the outer operand..
  Control. Python interprets that expression in the following way:
  >>> (True and (not False)) or ((not True) and False)
  This is because boolean operators, like arithmetic operators, have an order of operation:
  nothas the highest priority
  and
  orhas the lowest priority
  Truthy and Falsey Values:.
  Short-circuiting happens when the operator reaches an operand that allows them to make a conclusion about the expression. For example,
  and will short-circuit as soon as it reaches the first false value because it then knows that not all the values are true.
  If
  and and
  or do not short-circuit, they just return the last
  value; another way to remember this is that
  and and
  or always return the last
  thing they evaluate, whether they short circuit or not. Keep in mind that
  and and
  or
  don't always return booleans when using values other than
  True and
  False.)
  Getting Started Video
  This video provides some helpful direction for tackling the WWPD problems on this assignment.
  Q1: WWPD: Control
  Use Ok to test your knowledge with the following "What Would Python Display?" questions:
  python3 ok -q control -u
  Hint: Make sure your
  whileloop conditions eventually evaluate to a false value, or they'll never stop! Typing
  Ctrl-Cwill stop infinite loops in the interpreter.
  >>>
  >>> n = 3 >>> while n >= 0: ... n -= 1 ... print(n)______2 1 0 -1
  >>> positive = 28 >>> while positive: ... print("positive?") ... positive -= 3______Infinite Loop
  >>> positive = -9 >>> negative = -12 >>> while negative: ... if positive: ... print(negative) ... positive += 3 ... negative += 3______-12 -9 -6
  Q2: WWPD: Veritasiness
  Use Ok to test your knowledge with the following "What Would Python Display?" questions:
  python3 ok -q short-circuit >>> -1 and 1 > 0______True>>> 0 or False or 2 or 1 / 0______2
  >>> not 0______True>>> (1 + 1) and 1______1>>> 1/0 or True______Error>>> (True or False) and False______False
  Q3: Debugging Quiz!
  The following is a quick quiz on different debugging techniques you should use in this class. You should refer to this document to answer the questions!
  Run the following to run the quiz.
  python3 ok -q debugging-quiz -u
  Coding Practice
  Getting Started Video
  This video provides some helpful direction for tackling the coding problems on this assignment.
  Q4: Falling Factorial
  Let's write a function
  falling, which is a "falling" factorial
  that takes two arguments,
  n and
  k, and returns the product of
  k
  consecutive numbers, starting from
  n and working downwards.
  When
  k is 0, the function should return 1.
  def falling(n, k): """Compute the falling factorial of n to depth k. >>> falling(6, 3) # 6 * 5 * 4 120 >>> falling(4, 3) # 4 * 3 * 2 24 >>> falling(4, 1) # 4 4 >>> falling(4, 0) 1 """ "*** YOUR CODE HERE ***"
  Use Ok to test your code:
  python3 ok -q falling
  Q5: Sum Digits
  Write a function that takes in a nonnegative integer and sums its digits. (Using floor division and modulo might be helpful here!)
  def sum_digits(y): """Sum all the digits of y. >>> sum_digits(10) # 1 + 0 = 1 1 >>> sum_digits(4224) # 4 + 2 + 2 + 4 = 12 12 >>> sum_digits(1234567890) 45 >>> a = sum_digits(123) # make sure that you are using return rather than print >>> a 6 """ "*** YOUR CODE HERE ***"
  Use Ok to test your code:
  python3 ok -q sum_digits
  Submit
  Make sure to submit this assignment by running:
  python3 ok --submit
  Reminder: Please fill out the Lab 0 survey (also included at the beginning of this assignment): this survey
  Extra Practice
  These questions are optional and will not affect your score on this assignment. However, they are great practice for future assignments, projects, and exams. Attempting these questions is valuable in helping cement your knowledge of course concepts, and it's fun!
  Getting Started Video
  This video provides some helpful direction for tackling the optional problems on this assignment.
  Q6: WWPD: What If?
  Use Ok to test your knowledge with the following "What Would Python Display?" questions:
  python3 ok -q if-statements -u
  Hint:
  return) does not cause the function to exit!
  >>>'
  Q7:(2882) True >>> double_eights(880088) True >>> double_eights(12345) False >>> double_eights(80808080) False """ "*** YOUR CODE HERE ***"
  Use Ok to test your code:
  python3 ok -q double_eights