(Lab-1 Manual) CS-465 - Python Fundamentals
(Lab-1 Manual) CS-465 - Python Fundamentals
CS-465 Fall-2021
Fall 2021
Lab 1 - Manual
Python Installation & Python Language Fundamentals
V1.2
21/12/2020
2
CS-465 Fall-2021
1. Installing on Windows
1. Download the Anaconda installer
2. Double click the installer to launch
Note
If you encounter issues during installation, temporarily disable your anti-virus software during
install, then re-enable it after the installation concludes. If you installed for all users, uninstall
Anaconda and re-install it for your user only and try again.
3. Click Next.
4. Read the licensing terms and click “I Agree”.
5. Select an install for “Just Me” unless you’re installing for all users (which requires
Windows Administrator privileges) and click Next.
6. Select a destination folder to install Anaconda and click the Next button
Note
Install Anaconda to a directory path that does not contain spaces or unicode characters.
Do not install as Administrator unless admin privileges are required.
3
CS-465 Fall-2021
8. Choose whether to register Anaconda as your default Python. Unless you plan on
installing and running multiple versions of Anaconda or multiple versions of Python,
accept the default and leave this box checked.
9. Click the Install button. If you want to watch the packages Anaconda is installing, click Show
Details.
10. Click the Next button.
11. Optional: To install PyCharm for Anaconda, click on the link
to https://www.anaconda.com/pycharm. Or to install Anaconda without PyCharm, click the
Next button.
4
CS-465 Fall-2021
12. After a successful installation you will see the “Thanks for installing Anaconda” dialog box:
Anaconda Navigator
Anaconda Navigator is a graphical user interface that is automatically installed with Anaconda.
Navigator will open if the installation was successful.
Windows: Click Start, search or select Anaconda
Navigator from the menu.
5
CS-465 Fall-2021
2. Control Structures
Conditional Statements: if, else, elif
Often, we want to execute the code to perform some action based on a condition. For example, if
the condition is true, do something. We can get this done using “if, else, elif” statements.
Python’s “if” statement select actions to perform.
Let’s learn with a simple example.
True
Notice a block of whitespace before the print( ) statement, in the cell above. It is very
important in Python. Python does not use brackets in order to separate a block of code in the
execution statements, it uses white spaces instead. Like most of the other IDEs, jupyter notebook
automatically does this indentation of Python code after a colon.
If the condition is not satisfied (in the example below), print statement will not be
executed. Nothing will appear in the output.
So, in the above cell, the condition is not satisfied and we did not get True in the output. Well, do
we really know if the code was executed!
In such situation, we usually want our program to do something, even if the condition is not
satisfied, e.g., print False. This is where we (can) introduce else.
False
We can have multiple conditions in the code! Let’s introduce elif in such situation. * (elif is a short of
else-if and we can introduce many elif statements in the code.) *
6
CS-465 Fall-2021
Statement-02
** Very important thing to remember for elif statement. ** The code in the “if-elif(s)-else” block
will only execute the first True condition, it does not matter if you have other True conditions in
the code after your first True.
Let’s try another example here!
Statement-02
In the code above, although 2==2 is True, however, print(‘3rd statement’) will not be executed.
Since, the condition for print(‘2nd statement’) is also True and have already been executed!
After the user enters incorrect input. An exception will be thrown as shown below:
Let’s see how we can use try and except to handle this exception.