Skip to content

Commit c1e1379

Browse files
committed
add week 5 exercise
1 parent 3ecaae7 commit c1e1379

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

week5_exercise.ipynb

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"### 1. Write a format string (using `str.format()` and `f'string'`) that will take the following four element tuple:\n",
8+
"\n",
9+
"`( 2, 123.4567, 10000, 12345.67)`\n",
10+
"\n",
11+
"and produce:\n",
12+
" \n",
13+
"`'file_002 : 123.46, 1.00e+04, 1.23e+04'`"
14+
]
15+
},
16+
{
17+
"cell_type": "markdown",
18+
"metadata": {},
19+
"source": [
20+
"### 2. Write a python function that output the following formatted string based on the input iterable:\n",
21+
"\n",
22+
"`'The n numbers are: i1, i2, i3, ...'`\n",
23+
" \n",
24+
"where `n` is the number in the iterable and `i1, i2 ...` are the items inside the iterable. \n",
25+
"\n",
26+
"for example:\n",
27+
"\n",
28+
"`func([1, 2, 3])` will return `'The 3 numbers are: 1, 2, 3'`\n",
29+
"\n",
30+
"`func((6, 7, 8, 9))` will return `'The 4 numbers are: 6, 7, 8, 9'`"
31+
]
32+
},
33+
{
34+
"cell_type": "markdown",
35+
"metadata": {},
36+
"source": [
37+
"### 3. Write a similar function as the last one but it inputs variable-length arguments instead\n",
38+
"\n",
39+
"`func(1, 2, 3)` will return `'The 3 numbers are: 1, 2, 3'`\n",
40+
"\n",
41+
"`func(6, 7, 8, 9)` will return `'The 4 numbers are: 6, 7, 8, 9'`"
42+
]
43+
},
44+
{
45+
"cell_type": "markdown",
46+
"metadata": {},
47+
"source": [
48+
"### 4. Write a format string (f'string') that will take the following tuple and return the formatted string below:\n",
49+
"\n",
50+
"Tuple: `(4, 30, 2017, 2, 27)`\n",
51+
"\n",
52+
"Return: `'02 27 2017 04 30'`"
53+
]
54+
},
55+
{
56+
"cell_type": "markdown",
57+
"metadata": {},
58+
"source": [
59+
"### 5. Write a format string (f'string') that will take the following input and return the formatted string below:\n",
60+
"\n",
61+
"Input: `['oranges', 1.3, 'lemons', 1.1]`\n",
62+
" \n",
63+
"Return: `'The weight of an orange is 1.3 and the weight of a lemon is 1.1 and the total weight is 2.4'`"
64+
]
65+
},
66+
{
67+
"cell_type": "markdown",
68+
"metadata": {},
69+
"source": [
70+
"### 6. Write a function that will format each item in an input iterable object into a customized width \n",
71+
"\n",
72+
"syntax: `func(iterable, width)`\n",
73+
"\n",
74+
"for example:\n",
75+
" \n",
76+
"`func([1, 2, 3, 4, 5], 3)` return `' 1 2 3 4 5'`\n",
77+
"\n",
78+
"`func([1, 2, 3, 4, 5], 2)` return `' 1 2 3 4 5'`"
79+
]
80+
}
81+
],
82+
"metadata": {
83+
"kernelspec": {
84+
"display_name": "Python 3",
85+
"language": "python",
86+
"name": "python3"
87+
},
88+
"language_info": {
89+
"codemirror_mode": {
90+
"name": "ipython",
91+
"version": 3
92+
},
93+
"file_extension": ".py",
94+
"mimetype": "text/x-python",
95+
"name": "python",
96+
"nbconvert_exporter": "python",
97+
"pygments_lexer": "ipython3",
98+
"version": "3.7.6"
99+
}
100+
},
101+
"nbformat": 4,
102+
"nbformat_minor": 4
103+
}

0 commit comments

Comments
 (0)