From 669c5bd3698c164ede81b26419e02a74984af75e Mon Sep 17 00:00:00 2001 From: aravinds-arv Date: Fri, 20 Oct 2023 14:11:29 +0530 Subject: [PATCH] some more stylistic edits to lessons 0,1,2 admonitions for problems look better without the 'Problem' title, making all multiline codeblocks numbered.. except standard outputs, to keep them visually distinct from the actual 'code' blocks --- docs/chapter-0/lesson-0.md | 2 +- docs/chapter-1/lesson-1.1.md | 2 +- docs/chapter-1/lesson-1.4.md | 2 +- docs/chapter-1/lesson-1.5.md | 32 +++++++------- docs/chapter-1/lesson-1.6.md | 32 +++++++------- docs/chapter-2/lesson-2.1.md | 86 +++++++++++++++++------------------- docs/chapter-2/lesson-2.2.md | 6 +-- docs/chapter-2/lesson-2.3.md | 32 +++++++------- docs/chapter-2/lesson-2.4.md | 20 ++++----- 9 files changed, 105 insertions(+), 109 deletions(-) diff --git a/docs/chapter-0/lesson-0.md b/docs/chapter-0/lesson-0.md index 480f159..a81b06c 100644 --- a/docs/chapter-0/lesson-0.md +++ b/docs/chapter-0/lesson-0.md @@ -3,7 +3,7 @@ ## What is Python? To answer this question, we need to first ask _What is a programming language?_ A **programming language** is essentially a language in which you can tell your computer what to do. You will understand what that means as start programming. Every programming language has its own strengths and purposes. **Python** is a general-purpose programming language that can be used for a wide variety of purposes including but not limited to data science, automation, machine learning and software and web development. A typical python program to find the sum of the first 100 numbers looks like this: -```python +```python linenums="1" sum = 0 for number in range(1, 101): sum += number diff --git a/docs/chapter-1/lesson-1.1.md b/docs/chapter-1/lesson-1.1.md index dfcab5c..08ff352 100644 --- a/docs/chapter-1/lesson-1.1.md +++ b/docs/chapter-1/lesson-1.1.md @@ -40,7 +40,7 @@ Hello World! The sentence enclosed by the parentheses of the `#!py print()` function is called a **string**. A **string** is a sequence of characters enclosed in quotes. Strings can either be in single quotes or double quotes. However, a single quote can't be matched against a double quote to enclose a string. We have used single quotes in line 1 and double quotes in line 3. Both lines give identical outputs. The ability to use both single quotes and double quotes comes in handy in situations like this: -!!! question "Problem" +!!! question " " Print a string that has an apostrophe in it: ```pycon diff --git a/docs/chapter-1/lesson-1.4.md b/docs/chapter-1/lesson-1.4.md index f30a3c7..506f358 100644 --- a/docs/chapter-1/lesson-1.4.md +++ b/docs/chapter-1/lesson-1.4.md @@ -92,7 +92,7 @@ The interpreter throws a `TypeError`. The message accompanying the error is more The next exception that we will frequently encounter is `NameError`. -```python +```python linenums="1" print('There is no problem with this line') print(x ** 2) ``` diff --git a/docs/chapter-1/lesson-1.5.md b/docs/chapter-1/lesson-1.5.md index 487a2d5..461c07b 100644 --- a/docs/chapter-1/lesson-1.5.md +++ b/docs/chapter-1/lesson-1.5.md @@ -26,7 +26,7 @@ third line The following code will throw a `SyntaxError`: -```python +```python linenums="1" x = 'first line second line third line' @@ -35,7 +35,7 @@ print(x) This is where `'''` comes in: -```python +```python linenums="1" x = '''first line second line third line''' @@ -56,21 +56,21 @@ The `\n` character that you see above is called a newline character. Head to the The length of a string is the number of characters in it. Python provides a built-in function called `len` to find the length of a string: -```python +```python linenums="1" x = 'good' print(len(x)) ``` The code given above will give 4 as the output. If you are familiar with other programming languages, such as C, you might be aware of a character data type. Python doesn't have a separate data type for characters. A character in Python is represented by a string of length 1. In the following examples, `x` and `y` are strings of length 1. -```python +```python linenums="1" x = 'a' y = 'b' ``` We can also define empty strings: -```python +```python linenums="1" x = '' print(len(x)) ``` @@ -85,7 +85,7 @@ As expected, the length of the empty string is 0. We can concatenate two strings using the `+` operator. Concatenation is just a fancy term for joining two strings together: -```python +```python linenums="1" string1 = 'first' string2 = ',' string3 = 'second' @@ -105,7 +105,7 @@ first,second We can make multiple copies of a string and string them all together using the `*` operator: -```python +```python linenums="1" s = 'good' five_s = s * 5 print(five_s) @@ -119,7 +119,7 @@ goodgoodgoodgoodgood The `*` operator has made the string look too good! This is a fine demonstration of that ancient adage: "multiplication is repeated addition": -```python +```python linenums="1" s = 'good' s * 5 == s + s + s + s + s # This expression evaluates to True ``` @@ -130,7 +130,7 @@ s * 5 == s + s + s + s + s # This expression evaluates to True We can compare two strings. To begin with, we have the `==` operator: -```python +```python linenums="1" x = 'python' print(x == 'python', x == 'nohtyp') ``` @@ -143,7 +143,7 @@ True False Two strings are equal if and only if both of them represent exactly the same sequence of characters. Now, consider the following lines of code: -```python +```python linenums="1" print('good' > 'bad') print('nine' < 'one' ) print('a' < 'ab' < 'abc' < 'b') @@ -169,14 +169,14 @@ Python’s string type uses the Unicode standard for representing characters, wh Python provides a built-in function called `ord` that returns the code point of any given character. For example: -```python +```python linenums="1" print(ord('a'), ord('b')) print(ord('a'), ord('A')) ``` The output is: -```python +``` 97 98 97 65 ``` @@ -189,7 +189,7 @@ Now, we clearly see why `'a' < 'b'` returns `True`. This is because the code poi In Python, the backslash - `\` - is called the escape character. One of its uses is to represent certain white-space characters such as tabs and newlines. We will look at them one by one using the following examples: -```python +```python linenums="1" print('This is the first sentence.\nThis is the second sentence.') ``` @@ -202,7 +202,7 @@ This is the second sentence. `\n` is a newline character. Its effect is to introduce a new line. Note that even though there are two separate characters: `\` and `n`, `\n` is still regarded as a single character. To verify this, execute the following code. You should get 1 as the output. -```python +```python linenums="1" x = '\n' print(len(x)) ``` @@ -239,7 +239,7 @@ Now remove the backslash from the above string and try to print it. You will get A string is a substring of another string if the first string is contained in the second. For example, `'good'` is a substring of `'very good'`, whereas `'very good'` is not a substring of `'verygood'`. Python provides a keyword - `in` - which can be used to check if a given string is a substring of another string. For example: -```python +```python linenums="1" a = 'good' b = 'very good' present = a in b @@ -257,7 +257,7 @@ False `in` is a powerful keyword which has several other uses. It can also be used along with `not` in the following manner: -```python +```python linenums="1" a = 'abc' b = 'ab' print(a not in b) diff --git a/docs/chapter-1/lesson-1.6.md b/docs/chapter-1/lesson-1.6.md index 48abce5..e44c4ee 100644 --- a/docs/chapter-1/lesson-1.6.md +++ b/docs/chapter-1/lesson-1.6.md @@ -24,7 +24,7 @@ Given a word such as "world", we say that 'w' is the first letter in the word, ' Once this is defined, we can go ahead and access characters that are at a given position in a string: -```python +```python linenums="1" word = 'world' print(word[0]) print(word[1]) @@ -45,7 +45,7 @@ d Given a variable, say `word`, that holds a string literal, `word[i]` gives the character at index `i` in the string. Informally, this would be the letter at position `i + 1` in the string. Now, let us turn to the following code: -```python +```python linenums="1" word = 'world' print(word[5]) ``` @@ -61,7 +61,7 @@ IndexError: string index out of range The interpreter throws an `IndexError` as we are trying to access an index that is out of range. The length of the string is `5`. Since we start the index from `0`, the last character will be at index `4`. Anything greater than that is going to throw an error. Now, let us turn to the other end of the spectrum: -```python +```python linenums="1" word = 'world' print(word[-1]) ``` @@ -87,7 +87,7 @@ Image credit: [Wikipedia](https://en.wikipedia.org/wiki/Penrose_stairs#/media/Fi An index of `-1` points to the last element in the sequence. From this, we keep moving backwards until we reach the first element in the sequence which is at index `-5`. -```python +```python linenums="1" word = 'world' print(word[-1]) # ... please add the remaining lines! @@ -118,7 +118,7 @@ Given a string, we would like to extract the roll number of the student from it. ![slicing](../assets/images/img-030.png) -```python +```python linenums="1" email = 'CS_10_014@iitm.ac.in' roll = email[6 : 9] print(roll) @@ -128,7 +128,7 @@ The slicing operator - `start:stop` - will be our knife in slicing sequences! L Few more examples using the same string: -```python +```python linenums="1" email = 'CS_10_014@iitm.ac.in' branch = email[0 : 2] year = email[3 : 5] @@ -139,7 +139,7 @@ college = email[10 : 14] Slicing is quite powerful. If we want the institute roll number, including the branch, we could do the following: -```python +```python linenums="1" email = 'CS_10_014@iitm.ac.in' in_roll = email[ : 9] print(in_roll) @@ -147,7 +147,7 @@ print(in_roll) This outputs `CS_10_014`. If no starting index is specified in the slice, then `start` will default to `0`. Likewise, if no stopping index is specified, `stop` will default to the end of the string or `len(email)`. Now, consider: -```python +```python linenums="1" email = 'CS_10_014@iitm.ac.in' domain = email[-10 : ] print(domain) @@ -159,7 +159,7 @@ This outputs `iitm.ac.in`. Think for a while about the output. It is just a comb Using the above visual, we can now very easily process the following slices: -```python +```python linenums="1" word = 'world' print(word[-4 : 3]) print(word[1 : -2]) @@ -171,7 +171,7 @@ print(word[1 : -2]) Execute the following code and observe the output: -```python +```python linenums="1" word = 'some string' word[0] = 'S' ``` @@ -180,7 +180,7 @@ The interpreter throws a `TypeError` with the following error message: `'str' ob Note that this is different from the following: -```python +```python linenums="1" word = 'some string' word = 'Some string' ``` @@ -197,14 +197,14 @@ The number on the arrow represents the line number in the code. `word` binds to Consider the following problem: -!!! question "Problem" +!!! question " " Accept a sentence as input from the user and output the same sentence with the first letter in the sentence capitalized. For example, if the input is `'this is a chair.'`, the output should be `'This is a chair.'`. **Solution** -```python +```python linenums="1" sentence = input() cap_sentence = sentence.capitalize() print(cap_sentence) @@ -212,7 +212,7 @@ print(cap_sentence) `capitalize` is called a method. Methods are essentially functions, but they are defined for specific objects. So, they have to be called by using the object for which they have been defined. In the case of `capitalize`, it is a method that is defined for the `str` data type. If we try to call it using an `int` object, we will get an error: -```python +```python linenums="1" ##### Alarm! Wrong code snippet! a = 1 a.capitalize() @@ -221,12 +221,12 @@ a.capitalize() Getting back to the previous code snippet, `sentence.capitalize()` returns a string, which is then assigned to a new variable called `cap_sentence`. There are plenty of other methods associated with strings. Let us look at one more method which features in the solution to this interesting problem: -!!! question "Problem" +!!! question " " Check whether a given string is a valid name of a person. It is safe to assume that we are not thinking about Elon Musk's son, in which case, a name usually has only alphabets without any special characters and numbers. The method `isalpha` checks for just this requirement: -```python +```python linenums="1" # name is some pre-defined string valid = name.isalpha() print(valid) diff --git a/docs/chapter-2/lesson-2.1.md b/docs/chapter-2/lesson-2.1.md index be30000..8aee3fa 100644 --- a/docs/chapter-2/lesson-2.1.md +++ b/docs/chapter-2/lesson-2.1.md @@ -6,7 +6,7 @@ Variables are containers that are used to store values. Variables in Python are defined by using the assignment operator `=`. For example: -```python +```python linenums="1" x = 1 y = 100. z = "good" @@ -14,7 +14,7 @@ z = "good" Variables can also be updated using the assignment operator: -```python +```python linenums="1" x = 1 print('The initial value of x is', x) x = 2 @@ -40,7 +40,7 @@ variable_name = expression The assignment operator works from right to left. That is, the expression on the right is evaluated first. The value of this expression is assigned to the variable on the left. For example: -```python +```python linenums="1" x = 1 + 2 * 3 / 2 print(x) ``` @@ -53,13 +53,12 @@ The output is: Having a literal to the left of the assignment operator will result in an error: -
- ```python - ##### Alarm! Wrong code snippet! ##### - 3 = x - ##### Alarm! Wrong code snippet! ##### - ``` -
+ +```python linenums="1" +##### Alarm! Wrong code snippet! ##### +3 = x +##### Alarm! Wrong code snippet! ##### +``` This will throw the following error: @@ -76,7 +75,7 @@ The numbers on the arrow correspond to the line numbers in the code. The variabl As a final point, the assignment operator should not be confused with the equality operator: -```python +```python linenums="1" x = 2 # this is the assignment operator x == 2 # this is the equality operator ``` @@ -88,23 +87,25 @@ The assignment operator is used for creating or updating variables whereas the e !!! info "Dynamic Typing" Python supports what is called dynamic typing. In a dynamically typed language, a variable is simply a value bound to a name; the value has a type — like `int` or `str` — but the variable itself doesn't [^1]. For example: - ```python linenums="1" - a = 1 - print(type(a)) - a = 1 / 2 - print(type(a)) - a = "IIT Madras" - print(type(a)) - ``` - - The output is: - - ``` - - - - ``` - In the above example, `a` was initially bound to a value of type `#!py int`. After its update in line 3, it was bound to a value of type `#!py float` and after line 5, it becomes a `#!py str`. The image in the previous section will give a clearer picture of why this is the case. +```python linenums="1" +a = 1 +print(type(a)) +a = 1 / 2 +print(type(a)) +a = "IIT Madras" +print(type(a)) +``` + +The output is: + +``` + + + +``` + +In the above example, `a` was initially bound to a value of type `#!py int`. After its update in line 3, it was bound to a value of type `#!py float` and after line 5, it becomes a `#!py str`. The image in the previous section will give a clearer picture of why this is the case. + [^1]: Interestingly Python is both a dynamically typed and strongly typed language, head to this [wiki page](https://wiki.python.org/moin/Why%20is%20Python%20a%20dynamic%20language%20and%20also%20a%20strongly%20typed%20language) if you'd like to learn more about this. @@ -113,7 +114,7 @@ The assignment operator is used for creating or updating variables whereas the e When a variable that has already been defined is used in an expression, we say that the variable is being referenced. For example: -```python +```python linenums="1" x = 2 print(x * x, 'is the square of', x) ``` @@ -130,8 +131,6 @@ This is the output: NameError: name 'someVar' is not defined ``` - - ### Keywords and Naming Rules Keywords are certain words in the Python language that have a special meaning. Some of them are listed below: @@ -142,7 +141,7 @@ not, and, or, if, for, while, in, is, def, class We have already seen some of them - `not, and, or`. We will come across all these keywords in upcoming chapters. Keywords cannot be used as names for variables. For example, the following line of code will throw a SyntaxError when executed: -```python +```python linenums="1" ##### Alarm! Wrong code snippet! ##### and = 2 ##### Alarm! Wrong code snippet! ##### @@ -168,7 +167,7 @@ A few observations that directly follow from the above rules: Note that these are not merely conventions. Violating any one of these rules will result in a `SyntaxError`. As an example, the following code will throw a `SyntaxError` when executed: -```python +```python linenums="1" ##### Alarm! Wrong code snippet! ##### 3a = 1 ##### Alarm! Wrong code snippet! ##### @@ -178,8 +177,6 @@ Note that these are not merely conventions. Violating any one of these rules wil SyntaxError: invalid decimal literal ``` - - ### Reusing Variables Variables can be used in computing the value of other variables. This is something that will routinely come up in programming and data science. Consider the following sequence of mathematical equations. We wish to evaluate the value of `z` at `x = 10`: @@ -191,7 +188,7 @@ z=(x+1)(y+1) $$ This can be computed as follows: -```python +```python linenums="1" x = 10 y = x ** 2 z = (x + 1) * (y + 1) @@ -204,7 +201,7 @@ z = (x + 1) * (y + 1) Consider the following statement that defines two variables `x` and `y`. -```python +```python linenums="1" x = 1 y = 2 ``` @@ -223,7 +220,7 @@ x, y = 2, 1 To understand how this works, we need to get into the concept of packing and unpacking tuples, which we will visit in chapter 5. Treat this as a useful feature for the time being. Another way of doing multiple assignments is to initialize multiple variables with the same value: -```python +```python linenums="1" x = y = z = 10 print(x, y, z) ``` @@ -236,7 +233,7 @@ The output is: Though `x`, `y` and `z` start off by being equal, the equality is broken the moment even one of the three variables is updated: -```python +```python linenums="1" x = x * 1 y = y * 2 z = z * 3 @@ -249,13 +246,11 @@ The output is: 10 20 30 ``` - - ### Assignment Shortcuts Execute the code given below and observe the output. What do you think is happening? -```python +```python linenums="1" x = 1 x += 1 print(x) @@ -265,10 +260,10 @@ print(x) > `x += a` > -> Increment the value of `x` by `a`. In other words, add `a` to `x` and store the result in `x`. It is equivalent to the statement `x = x + a`. +> Increments the value of `x` by `a`. In other words, add `a` to `x` and store the result in `x`. It is equivalent to the statement `x = x + a`. This is not just limited to the addition operator. The following table gives a summary of the shortcuts for some of the arithmetic operators: - +
| Shortcut | Meaning | | --------- | ------------ | | `x += a` | `x = x + a` | @@ -277,10 +272,11 @@ This is not just limited to the addition operator. The following table gives a s | `x /= a` | `x = x / a` | | `x %= a` | `x = x % a` | | `x **= a` | `x = x ** a` | +
Note that the arithmetic operator must always come before the assignment operator in a shortcut. Swapping them will not work: -```python +```python linenums="1" x = 1 x =+ 1 print(x) diff --git a/docs/chapter-2/lesson-2.2.md b/docs/chapter-2/lesson-2.2.md index dac8645..4cc21da 100644 --- a/docs/chapter-2/lesson-2.2.md +++ b/docs/chapter-2/lesson-2.2.md @@ -6,7 +6,7 @@ Accepting input from the user routinely happens in programming. Any piece of sof Python provides a built-in function called `#!py input()` to accept input from the user. This is a simple yet powerful function: -```python +```python linenums="1" x = input() print('The input entered by the user is', x) ``` @@ -20,14 +20,14 @@ The input entered by the user is 1 Sometimes we may want to prompt the user to enter a particular type of input. This can be done by passing the instruction as an argument to the input function: -```python +```python linenums="1" x = input('Enter an integer between 0 and 10: ') print('The number entered by the user is', x) ``` Let us now look at the type of the variable `x`: -```python +```python linenums="1" x = input() print('The input entered by the user is of type', type(x)) ``` diff --git a/docs/chapter-2/lesson-2.3.md b/docs/chapter-2/lesson-2.3.md index 279626c..ab71086 100644 --- a/docs/chapter-2/lesson-2.3.md +++ b/docs/chapter-2/lesson-2.3.md @@ -4,7 +4,7 @@ Suppose you had to solve the following problem: -!!! question "Problem" +!!! question " " Accept an integer as input from the user. If the number is greater than zero, print `positive` and if number is less than zero, print `negative`, else print `zero`. This problem can solved by so called Conditional Statements. Conditional Statements is a very important concept in Computer Science in general and are the building blocks to solutions for very complex problems. Conditional Statements, as the name suggests, allow for conditional execution of code. We will we see what this means in detail in the coming sections. @@ -13,7 +13,7 @@ This problem can solved by so called Conditional Statements. Conditional Stateme ### if statement Let's start off with a simpler version of the earlier problem -!!! question "Problem" +!!! question " " Accept an integer as input from the user. If the number is greater than zero, print `non-negative`. `#!py if` is a keyword in Python. The text adjacent to `#!py if` is a boolean expression, usually called the **if-condition** or just the **condition**. Line-3 is the body of `#!py if`. If the condition evaluates to `True`, then line-3 is executed. If it is `False`, then line-3 doesn't get executed. The following diagram captures the terms that have been introduced: @@ -49,7 +49,7 @@ Lines 3-5 in the following codes make up the **if-block**. Lines 4 and 5 which a ``` The condition is `True`. So lines 4 and 5 are going to be executed. Once we exit the if-block, the interpreter will resume execution from line 6. The output will be: - ``` linenums="1" + ``` non-negative inside if outside if @@ -66,7 +66,7 @@ Lines 3-5 in the following codes make up the **if-block**. Lines 4 and 5 which a ``` The condition is `False`. So, lines 4 and 5 are *not* going to be executed. The interpreter will skip the body of `if` and directly move to line 6. The output will be - ``` linenums="1" + ``` outside if ``` @@ -74,7 +74,7 @@ Lines 3-5 in the following codes make up the **if-block**. Lines 4 and 5 which a Let us add one more level of complexity to the problem. -!!! question "Problem" +!!! question " " Accept an integer as input from the user. If the number is greater than or equal to zero, print: `non-negative`. If the number is less than zero, print `negative`. `#!py else` is a keyword in Python. When the if-condition evaluates to `True`, the statements inside the body of the if-block are evaluated. When the condition evaluates to `False`, the statements inside the body of the else-block are evaluated. @@ -103,7 +103,7 @@ Points to remember: The following code demonstrates the last two points: -```python +```python linenums="1" ##### Alarm! Wrong code snippet! ##### else: print(1) @@ -124,7 +124,7 @@ else x < y: This final tool will help us solve the original problem: -!!! question "Problem" +!!! question " " Accept an integer as input from the user. If the number is greater than zero, print `positive` and if number is less than zero, print `negative`, else print `zero`. `#!py elif` is a keyword in Python. It is a shorthand for else-if. With this final weapon in our conditional statements arsenal, we can solve the problem as thus @@ -169,13 +169,13 @@ A visual representation of the process is given below: The general syntax: -``` -if : - -elif : - +```python linenums="1" +if : + +elif : + else: - + ``` Some features to note: @@ -191,12 +191,12 @@ Some features to note: Consider the following problem: -!!! question "Problem" +!!! question " " Accept three distinct integers as input from the user. If the numbers have been entered in ascending order, print `in ascending order`. If not, print `not in ascending order`. An incomplete solution is given below: -```python +```python linenums="1" # Incomplete solution x = int(input()) y = int(input()) @@ -234,7 +234,7 @@ Having a conditional statement inside another conditional statement is called ne Consider the following snippet of code: -```python +```python linenums="1" x = int(input()) if x % 5 == 0: output = 'the number is divisible by 5' diff --git a/docs/chapter-2/lesson-2.4.md b/docs/chapter-2/lesson-2.4.md index a2e99a5..836c3a6 100644 --- a/docs/chapter-2/lesson-2.4.md +++ b/docs/chapter-2/lesson-2.4.md @@ -8,12 +8,12 @@ A library is a collection of functions that share a common theme. This is a loos Consider the following problem: -!!! question "Problem" +!!! question " " In the year $3000$, $15^{\text{th}}$​ August will fall on which day of the week? Python to the rescue: -```python +```python linenums="1" import calendar calendar.prmonth(3000, 8) ``` @@ -34,7 +34,7 @@ Mo Tu We Th Fr Sa Su `calendar` is a collection of functions that are related to calendars. `#!py prmonth()` is one such function. It accepts `` and ``, as input and displays the calendar for `` in the year ``. If we want to use a function in `calendar`, we must first import the library. Let us see what happens if skip this step: -```python +```python linenums="1" # import calendar calendar.prmonth(3000, 8) ``` @@ -42,6 +42,8 @@ calendar.prmonth(3000, 8) It gives the following error: ```pycon +Traceback (most recent call last): + File "", line 2, in NameError: name 'calendar' is not defined ``` @@ -53,7 +55,7 @@ To access a function defined inside a library, we use the following syntax: Another way to solve the problem is to use the function `weekday`: -```python +```python linenums="1" import calendar print(calendar.weekday(3000, 8, 15)) ``` @@ -70,18 +72,16 @@ The output of the above code is `4`. Days are mapped to numbers as follows: | Saturday | 5 | | Sunday | 6 | - - ### `time` Let us now try to answer this hypothetical question: -!!! question "Problem" +!!! question " " You are stranded on an island in the middle of the Indian Ocean. The island has a computing device that has just one application installed in it: a Python interpreter. You wish to know the current date and time. **Solution** -```python +```python linenums="1" from time import ctime print('The current time is:', ctime()) ``` @@ -94,7 +94,7 @@ The current time is: Fri Apr 2 12:24:43 2021 The syntax of the import statement in line-1 looks different. `from` is a new keyword. The first line of the code is essentially doing the following: from the library called `time` import the function called `ctime`. This way of importing functions is useful when we need just one or two functions from a given library: -```python +```python linenums="1" from time import ctime, sleep print('Current time is:', ctime()) print('I am going to sleep for 10 seconds') @@ -110,7 +110,7 @@ print('Current time is:', ctime()) As a fun exercise, consider the following code: -``` +```python import this ```