Skip to content

Instantly share code, notes, and snippets.

@mguijarr
Last active October 27, 2021 05:49
Show Gist options
  • Save mguijarr/084d3a6f5e658be951af053c47ff77bb to your computer and use it in GitHub Desktop.
Save mguijarr/084d3a6f5e658be951af053c47ff77bb to your computer and use it in GitHub Desktop.
Python job interview questions for BLISS COD

BLISS COD test

1. Python is... (multiple answers ok)

  • a system programming language
  • a compiled language
  • strongly typed
  • dynamically typed
  • object-oriented

2. What are the first 4 results printed by this code:

a, b = 0, 1
while b < 1000:
    print b
    a, b = b, a+b

3. Using list comprehension, write a function that returns integers divisible by 7 between 0 and ‘n’

4. Write a context manager to display the wall-clock time taken by a code block

5. Explain the main difference between the 2 versions of the code below, which one executes faster ?

Version 1

import requests

urls = (
        'http://cnn.com',
        'http://nytimes.com',
        'http://google.com',
        'http://leagueoflegends.com',
        'http://python.org',
    )

def download(urls):
    return [requests.get(url) for url in urls]
    
download(urls)

Version 2, using asyncio

import asyncio
import aiohttp

urls = (
        'http://cnn.com',
        'http://nytimes.com',
        'http://google.com',
        'http://leagueoflegends.com',
        'http://python.org',
    )

async def download_one(session, url):
    async with session.get(url) as res:
        return await res.read()

async def download(urls):
    async with aiohttp.ClientSession() as session:
        await asyncio.gather(*[download_one(session, url) for url in urls])

asyncio.run(download(urls))

6. Explain briefly the difference between a thread and a coroutine run by a scheduler.

7. Fix the following test, to make it pass and have the desired output:

import pytest
import gevent
import time

def test_gevent_code_output(capsys):
  def func():
      for i in range(3):
          print(i)
          time.sleep(1)
          
  tasks = [gevent.spawn(func) for _ in range(2)]
  
  gevent.joinall(tasks)

  assert capsys.readouterr().out == "1\n1\n2\n2\n3\n3\n"

8. Add the synchronization code in the program below, in order to ensure the thread is ready before execution continues in "main" (hint: add a "wait_ready" method to the A class and call it in "main").

import threading
import time

class A(threading.Thread):
  def __init__(self, sleep_time):
      super().__init__()
      self.sleep_time = sleep_time

  def run(self):
      print("Not ready yet")
      time.sleep(0.1)
      print("I am ready !")
      time.sleep(self.sleep_time)

def main():
  a_thread = A(3)
  a_thread.start()
  print("Add the code, for this line to be always printed *after* 'I am ready !'")
  a_thread.join()
  
main()

9. Write the Python code for a simulation Shutter class. A Shutter is a device that can open (beam passes through) or close (beam is stopped). Do not forget about the state.

10. In Object-Oriented Programming, what are the concepts of inheritance and composition ?

11. Given an array a = [[1,2,3],[3,4,5],[23,45,1]] ; using NumPy, find the sum of every row in array a.

12. Read the following file into a NumPy array (replace absent values with 0):

1, 2, 3, 4, 5
6,  ,  , 7, 8
,  , 9, 10,11

13. Explain what "serialization" means, and what it is used for ?

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