Review of Python — Part 1A

Example

→ A Python 3 session

Suggested Exercises

  1. Write a Python function with one argument, eggs, which uses an "if" statement to prints "fine" if the value of eggs is 29 or greater, prints "really?" if eggs is less than 29 but not less than 15, and prints "shucks" if eggs is less than 15.
  2. Write a Python "for" statement which prints "Happy birthday!" 9 times.
  3. Do the same with a "while" statement.
  4. Write a Python function which, given an argument names which is a list of strings, prints "Happy birthday, ⟨name⟩" for each ⟨name⟩ in names. For example, if names contains James and Jane, the output would be
    Happy birthday, James
    Happy birthday, Jane

→ Solutions