Skip to content

Instantly share code, notes, and snippets.

@imbingz
Created May 11, 2019 21:16
Show Gist options
  • Save imbingz/c503822467788594917827f64013c5a1 to your computer and use it in GitHub Desktop.
Save imbingz/c503822467788594917827f64013c5a1 to your computer and use it in GitHub Desktop.
Created on Cognitive Class Labs
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3\n",
"3 devided by 3 is 1.0\n",
"6\n",
"6 devided by 3 is 2.0\n",
"9\n",
"9 devided by 3 is 3.0\n"
]
}
],
"source": [
"for i in range(3, 10, 3):\n",
" print(i)\n",
" quotient = i / 3\n",
" print(f\"{i} devided by 3 is {float(quotient)}\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10 divided by 2 is 5.0\n",
"11 divided by 2 is 5.5\n",
"12 divided by 2 is 6.0\n",
"13 divided by 2 is 6.5\n",
"14 divided by 2 is 7.0\n"
]
}
],
"source": [
"for i in range(10, 15):\n",
" quotient = i / 2\n",
" print(f\"{i} divided by 2 is {float(quotient)}\")"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-5\n",
"-4\n",
"-3\n",
"-2\n",
"-1\n",
"0\n",
"1\n",
"2\n",
"3\n",
"4\n"
]
}
],
"source": [
"# Write a for loop that prints out all the element between -5 and 5 using the range function.\n",
"\n",
"for i in range(-5, 5):\n",
" print(i)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"rock\n",
"R&B\n",
"Soundtrack\n",
"R&B\n",
"soul\n",
"pop\n"
]
}
],
"source": [
"# Print the elements of the following list. Make sure to follow Python conventions\n",
"\n",
"Genres=[ 'rock', 'R&B', 'Soundtrack', 'R&B', 'soul', 'pop']\n",
"for genre in Genres:\n",
" print(genre)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10\n",
"10\n",
"9.5\n",
"10\n",
"8\n",
"7.5\n"
]
}
],
"source": [
"# Write a while loop to display the values of the Rating of an album playlist stored in the list PlayListRatings. If the score is less than 6, exit the loop. The list PlayListRatings is given by: \n",
"\n",
"PlayListRatings = [10, 9.5, 10, 8, 7.5, 5, 10, 10] \n",
"\n",
"rating = PlayListRatings[0]\n",
"i = 0 \n",
"\n",
"while (rating >= 6):\n",
" print (rating)\n",
" rating = PlayListRatings[i]\n",
" i = i + 1\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Write a while loop to copy the strings 'orange' of the list squares to the list new_squares. Stop and exit the loop if the value on the list is not 'orange':\n",
"\n",
"squares = [\"orange\", \"orange\", \"purple\", \"blue\", \"orange\"]\n",
"\n",
"new_squares = []\n",
"i = 0\n",
"\n",
"while (squares[i] == \"orange\"):\n",
" new_squares.append(squares[i])\n",
" i = 0 + 1\n",
"print(new_squares)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"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.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment