Skip to content

Instantly share code, notes, and snippets.

@balu
Created January 28, 2021 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balu/ef60f91681d7d92ff8e7a777faeb2fe9 to your computer and use it in GitHub Desktop.
Save balu/ef60f91681d7d92ff8e7a777faeb2fe9 to your computer and use it in GitHub Desktop.
  1. Write a function countdown that takes a number n as input and prints the countdown from n to 0.

  2. The computer is way too fast. To a human observer, it would seem that all numbers in the countdown are printed at once. Figure out, using your favourite search engine, what can be done to add a delay in between numbers.

  3. Modify the yes function so that it takes a number n and prints y exactly n times.

    Remark: In the old days when everyone used to live inside the terminal, this yes function was used to automatically answer "yes" to all questions produced by prompt. See the yes program wikipedia entry.

  4. Suppose python didn't provide a multiplication operator. Show how to define a mul function that takes two numbers and returns its product. The mul function should not use any multiplicative operators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment