Skip to content

Instantly share code, notes, and snippets.

@Bl3f
Last active January 7, 2016 15:27
Show Gist options
  • Save Bl3f/e2460e5a41307213bd65 to your computer and use it in GitHub Desktop.
Save Bl3f/e2460e5a41307213bd65 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Simple quiz on Python introduction"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The aim of this is only to see if you understood everything. No traps!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Q1. Assign to `a` and `b` respectivily, the int `5` and the string `\"BoNjour\"`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"assert a == 5\n",
"assert b == \"BoNjour\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Q2. Do the following calcul: multiply 32 by 2 and add 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"assert result == ord('A')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Q3. Create a list with at least 5 ints (list will begin with 6)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"__tmp = len(result)\n",
"assert __tmp >= 5"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Q4. Append an item to the list"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"assert __tmp < len(result)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Q5. Get the first item of the list in `first_item` variable"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"assert first_item == ord('\\x06')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Q6. Compute the sum of the list with 2 different method and check if you have the same value"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Q7. Write a boolean condition always true"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Q8. Write a boolean condition always false"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Q9. Fix the issue (or the issues) of this program and explain the purpose"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"d = {3 : [], 5: [], 7: []}\n",
"for i in range(100)\n",
" for k in d.keys():\n",
" if i % k = 0:\n",
" d[k].append(i)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Q10. Create a simple dictionnary"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Q10.1 Display the dictionnary keys"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Q10.2 Display dictionnary values"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Q10.3 Access to an dict item"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"QA. Write a function that get the mean of a list given in parameter. We will call the function *my_mean*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def ma_moyenne(elements):\n",
" pass"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"l1 = [2, 3, 4, 6, 7, 80]\n",
"assert ma_moyenne(l1) == 17.00"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"QB. Get the world population (https://www.google.com/fusiontables/DataSource?docid=1MYXX1aUrAW4CVWQwewqU4c6-Pti8Nk0BSklNYHY) and count how many countries do we have inside + the total world population."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment