{
“cells”: [
{
“cell_type”: “markdown”,
“metadata”: {},
“source”: [
“# Python 3.6+\n”,
“We assume you are using Python 3.6+ in this course”
]
},
{
“cell_type”: “markdown”,
“metadata”: {},
“source”: [
“# Question 1\n”,
“\n”,
“Review list comprehension if needed: https://realpython.com/list-comprehension-python/\n”,
“\n”,
“The formula for list comprehension is: `new_list = [expression for member in iterable (if conditional)]`\n”,
“\n”,
“You need to do the following:\n”,
“1. use a loop to create a list of 5 cube numbers and print the list:[0, 1, 8, 27, 64]\n”,
“2. use list comprehension to create the same list\n”,
“3. find the postions of all vowels in a sentence using list comprehension”
]
},
{
“cell_type”: “code”,
“execution_count”: null,
“metadata”: {},
“outputs”: [],
“source”: [
“# use a loop to create a list\n”,
“cubes = []”
]
},
{
“cell_type”: “code”,
“execution_count”: null,
“metadata”: {},
“outputs”: [],
“source”: [
“# use list comprehension to create the same list”
]
},
{
“cell_type”: “code”,
“execution_count”: null,
“metadata”: {},
“outputs”: [],
“source”: [
“# find the positions of all vowels in the following sentence using list comprehension\n”,
“sentence = \”Talk is cheap. Show me the code – Linus Torvalds\””
]
},
{
“cell_type”: “markdown”,
“metadata”: {},
“source”: [
“# Question 2\n”,
“You need to use to format strings\n”,
“\n”,
“Write a program using the \”f-strings\” (https://realpython.com/python-f-strings/), conditional statements, user input function to convert temperatures to and from Celsius, Fahrenheit. [Formula: Celsius/5 = (Fahrenheit – 32)/9]\n”,
“\n”,
“Hint: you may need int() function\n”,
“\n”,
“An example program output:\n”,
““`\n”,
“Please enter the temperature: 60\n”,
“Is this Celsius or Fahrenheit? C\n”,
“60C is 140 in Fahrenheit\n”,
““`\n”,
“\n”,
“Another example:\n”,
““`\n”,
“Please enter the temperature: 45\n”,
“Is this Celsius or Fahrenheit? F\n”,
“45F is 7 in Celsius\n”,
““`”
]
},
{
“cell_type”: “code”,
“execution_count”: null,
“metadata”: {},
“outputs”: [],
“source”: [
“# an example of f-strings and user input function\n”,
“username = input(‘What\\’s your name?’)\n”,
“print(f’Welcome! {username}’)”
]
},
{
“cell_type”: “code”,
“execution_count”: null,
“metadata”: {},
“outputs”: [],
“source”: [
“# complete your program here”
]
},
{
“cell_type”: “code”,
“execution_count”: null,
“metadata”: {},
“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.7.6”
}
},
“nbformat”: 4,
“nbformat_minor”: 4
}