Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 28

Introduction to Python (Lab)

Name: _______________________________________________

Roll Number: _________________________________________

Computer Science Department


IQRA University, Karachi
INDEX

Lab No. Objectives Date Signature

1. The purpose of this lab is to get you familiar with Python and
its IDE
2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

12

13

14
FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

Course Name (Course Code) __________________ Semester ________ Batch _______


Name of Student: ___________________________________Roll No. ______________

Lab Description & Score


Programming/
1. Software Handling
Simulations
Results Lab Report Score
( )/2 ( )/2 ( )/1 ( )/10
( )/5

Programming/
2. Software Handling
Simulations
Results Lab Report Score
( )/2 ( )/2 ( )/1 ( )/10
( )/5

Programming/
3. Software Handling
Simulations
Results Lab Report Score
( )/2 ( )/2 ( )/1 ( )/10
( )/5

Programming/
4. Software Handling
Simulations
Results Lab Report Score
( )/2 ( )/2 ( )/1 ( )/10
( )/5

Programming/
5. Software Handling
Simulations
Results Lab Report Score
( )/2 ( )/2 ( )/1 ( )/10
( )/5

Programming/
6. Software Handling
Simulations
Results Lab Report Score
( )/2 ( )/2 ( )/1 ( )/10
( )/5

Programming/
7. Software Handling
Simulations
Results Lab Report Score
( )/2 ( )/2 ( )/1 ( )/10
( )/5

Programming/
8. Software Handling
Simulations
Results Lab Report Score
( )/2 ( )/2 ( )/1 ( )/10
( )/5

Programming/
9. Software Handling
Simulations
Results Lab Report Score
( )/2 ( )/2 ( )/1 ( )/10
( )/5

Programming/
10. Software Handling
Simulations
Results Lab Report Score
( )/2 ( )/2 ( )/1 ( )/10
( )/5

Programming/
11. Software Handling
Simulations
Results Lab Report Score
( )/2 ( )/2 ( )/1 ( )/10
( )/5
12.
Software Handling Programming/ Results Lab Report Score
( )/2 Simulations ( )/2 ( )/1 ( )/10

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

( )/5

Programming/
13. Software Handling
Simulations
Results Lab Report Score
( )/2 ( )/2 ( )/1 ( )/10
( )/5

Programming/
14. Software Handling
Simulations
Results Lab Report Score
( )/2 ( )/2 ( )/1 ( )/10
( )/5
TOTAL SCORE = 140 OBTAINED SCORE

Overall Score: ___________ out of 140 Examined by: _________________


Overall Formula= (Obtained Score / Total Score) x 50 (Name and Signature of Concerned)

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

General Laboratory Procedure


While there is no specific document to be submitted at the beginning of the Lab –unless your instructor
advises you otherwise-, you are expected to read the experiment fully before you come to the laboratory?
Interestingly, you can even try parts of the experiment at home. Here is a list of programs that will equip
you with a virtual lab at your home:

Troubleshooting
Things will not always go as expected; this is the nature of the learning process. While conducting the
Experiment think before you do anything. If you do so you will avoid wasting time going down dead-
end streets. Be logical and systematic. First, look for obvious errors that are easy to fix. Is your measuring
device correctly set and connected? Are you looking at the proper scale? Is the power supply set for the
correct voltage? Is the signal generator correctly set and connected? How are the variables in the code
set? Is there a syntax error? And so on. Next, check for obvious misconnections or broken connections, at
least in simple circuits.
As you work through your circuit, use your Lab Manual record tests and changes that you make as you go
along; don't rely on your memory for what you have tried. Identify some test points in the system at
which you know what the signal should be and work your way backwards from the output through the
test points until you find a good signal.

Neatness
When you have finished for the day, return all modules to their proper storage bins, return all test leads
and probes to their storage racks, return all equipment to its correct location, and clean up the lab station.
If appropriate switch off the unneeded equipment. Save your files in the Computer and on any USB
device for your records because you might not get the same PC System again for the next experiment.
Also email your file contents to your email address as a backup.

Laboratory Safety

Always pay attention to what you are doing and you’re surrounding during the experiments, notify the
Instructor for any unlikely event or mishap, and leave the Laboratory with the permission of Instructor
immediately.
All students must read and understand the information in this document with regard to laboratory safety
and emergency procedures prior to the first laboratory session.

Your personal laboratory safety depends mostly on YOU. Efforts have been made to address
situations that may pose a hazard in the lab but the information and instructions provided cannot be
considered all-inclusive.

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

Students must adhere to written and verbal safety instructions throughout the academic term. Since
additional instructions may be given at the beginning of laboratory sessions, it is important that all
students arrive at each session on time. With good judgment, the chance of an accident in this course is
very small. Nevertheless, research and teaching workplaces (labs, shops, etc.) are full of potential hazards
that can cause serious injury and or damage to the equipment. Working alone and unsupervised in
laboratories is forbidden if you are working with hazardous substances or equipment. With prior
approval, at least two people should be present so that one can shut down equipment and call for help in
the event of an emergency. Safety training and/or information should be provided by a faculty member,
teaching assistant, lab safety contact, or staff member at the beginning of a new assignment or when a
new hazard is introduced into the workplace.

Emergency Response
1. It is your responsibility to read safety and fire alarm posters and follow the instructions during an
emergency
2. Know the location of the fire extinguisher, eye wash, and safety shower in your lab and know how to
use them.
3. Notify your instructor immediately after any injury, fire or explosion, or spill.
4. Know the building evacuation procedures.

Common Sense
Good common sense is needed for safety in a laboratory. It is expected that each student will work in a
responsible manner and exercise good judgment and common sense. If at any time you are not sure how
to handle a particular situation, ask your Teaching Assistant or Instructor for advice DO NOT TOUCH
ANYTHING WITH WHICH YOU ARE NOT COMPLETELY FAMILIAR!!! It is always better to
ask questions than to risk harm to yourself or damage to the equipment.

Personal and General laboratory safety


1. Never eat, drink, or smoke while working in the laboratory.
2. Read labels carefully.
3. Do not use any equipment unless you are trained and approved as a user by your supervisor.
4. Wear safety glasses or face shields when working with hazardous materials and/or equipment.
5. Wear gloves when using any hazardous or toxic agent.
6. Clothing: When handling dangerous substances, wear gloves, laboratory coats, and safety shield or
glasses. Shorts and sandals should not be worn in the lab at any time. Shoes are required when
working in the machine shops.
7. If you have long hair or loose clothes, make sure it is tied back or confined.
8. Keep the work area clear of all materials except those needed for your work. Coats should be hung in
the hall or placed in a locker. Extra books, purses, etc. should be kept away from equipment that
requires air flow or ventilation to prevent overheating.
9. Disposal - Students are responsible for the proper disposal of used material if any in appropriate
containers.
10. Equipment Failure - If a piece of equipment fails while being used, report it immediately to your lab
assistant or tutor. Never try to fix the problem yourself because you could harm yourself and others.
11. If leaving a lab unattended, turn off all ignition sources and lock the doors.
12. Never pipette anything by mouth.

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

13. Clean up your work area before leaving.


14. Wash hands before leaving the lab and before eating.
15. Unauthorized person(s) shall not be allowed in a laboratory for any reason.

Electrical safety
1. Obtain permission before operating any high voltage equipment.
2. Maintain an unobstructed access to all electrical panels.
3. Wiring or other electrical modifications must be referred to the Electronics Shop or the Building
Coordinator.
4. Avoid using extension cords whenever possible. If you must use one, obtain a heavy- duty one that is
electrically grounded, with its own fuse, and install it safely. Extension cords should not go under
doors, across aisles, be hung from the ceiling, or plugged into other extension cords.
5. Never, ever modify, attach or otherwise change any high voltage equipment.
6. Always make sure all capacitors are discharged (using a grounded cable with an insulating handle)
before touching high voltage leads or the "inside" of any equipment even after it has been turned off.
Capacitors can hold charge for many hours after the equipment has been turned off.
7. When you are adjusting any high voltage equipment or a laser which is powered with a high voltage
supply, USE ONLY ONE HAND. Your other hand is best placed in a pocket or behind your back.
This procedure eliminates the possibility of an accident where high voltage current flows up one arm,
through your chest, and down the other arm.
8. Discard damaged cords, cords that become hot, or cords with exposed wiring.
9. Before equipment is energized ensure, (1) circuit connections and layout have been checked by a
Teaching Assistant (TA) and (2) all colleagues in your group give their assent.
10.Know the correct handling, storage and disposal procedures for batteries, cells, capacitors, inductors
and other high energy-storage devices.
11.Experiments left unattended should be isolated from the power supplies. If for a special reason, it must
be left on, a barrier and a warning notice are required.
12.Equipment found to be faulty in any way should be reported to the Lab Engineer immediately and
taken out of service until inspected and declared safe.
13.Voltages above 50 V rms AC and 120 V DC are always dangerous. Extra precautions should be
considered as voltage levels are increased.
14.Never make any changes to circuits or mechanical layout without first isolating the circuit by
switching off and removing connections to power supplies.
15.Know what you must do in an emergency.
16.Emergency Power Off: Every lab is equipped with and Emergency Power Off System.
17.Only authorized personnel are permitted to reset power once the Emergency Power Off system has
been engaged.

Electrical Emergency Response


The following instructions provide guidelines for handling two types of electrical emergencies:

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

1. When someone suffers serious electrical shock, he or she may be knocked unconscious. If the victim is
still in contact with the electrical current, immediately turn off the electrical power source. If you
cannot disconnect the power source, depress the Emergency Power Off switch.
2. Do not touch a victim that is still in contact with a live power source; you could be electrocuted.
3. Have someone call for emergency medical assistance immediately. Administer first-aid, as
appropriate.
4. If an electrical fire occurs, try to disconnect the electrical power source, if possible. If the fire is small
and you are not in immediate danger; and you have been properly trained in fighting fires, use the
correct type of fire extinguisher to extinguish the fire. When in doubt, push in the Emergency Power
Off button.
5. NEVER use water to extinguish an electrical fire.

Mechanical safety
1. When using compressed air, use only approved nozzles and never direct the air towards any person.
2. Guards on machinery must be in place during operation.
3. Exercise care when working with or near hydraulically- or pneumatically-driven equipment. Sudden or
unexpected motion can inflict serious injury.

Additional Safety Guidelines


1. Never do unauthorized experiments.
2. Never work alone in laboratory.
3. Keep your lab space clean and organized.
4. Do not leave an on-going experiment unattended.
5. Always inform your instructor if you break a thermometer. Do not clean
mercury yourself!!
6. Never taste anything. Never pipette by mouth; use a bulb.
7. Never use open flames in laboratory unless instructed by TA.
8. Check your glassware for cracks and chips each time you use it. Cracks could cause the glassware to
fail during use and cause serious injury to you or lab mates.
9. Maintain unobstructed access to all exits, fire extinguishers, electrical panels, emergency showers, and
eye washes.
10. Do not use corridors for storage or work areas.
11. Do not store heavy items above table height. Any overhead storage of supplies on top of cabinets
should be limited to lightweight items only. Also, remember that a 36" diameter area around all fire
sprinkler heads must be kept clear at all times.
12. Areas containing lasers, biohazards, radioisotopes, and carcinogens should be posted accordingly.
However, do not post areas unnecessarily and be sure that the labels are removed when the hazards are
no longer present.
13. Be careful when lifting heavy objects. Only shop staff may operate forklifts or cranes.
14. Clean your lab bench and equipment, and lock the door before you leave the laboratory.

Clothing

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

1. Dress properly during a laboratory activity.


2. Long hair, dangling jewelry, and loose or baggy clothing are a hazard in the laboratory.
3. Long hair must be tied back, and dangling jewelry and baggy clothing must be secured.
4. Shoes must completely cover the foot.
5. No sandals allowed on lab days.
6.A lab coat or smock should be worn during laboratory experiments.

Accidents and Injuries


1.Do not panic.
2.Report any accident (spill, breakage, etc.) or injury (cut, burn, etc.) to the
teacher immediately, no matter how trivial it seems.
3.If you or your lab partner is hurt, immediately (and loudly) yell out the
teacher's name to get the teacher's attention.

General Warning Signs

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

Lab-01
Introduction to Python
Objectives:
The purpose of this lab is to get you familiar with Python and its IDE.

Apparatus:
Hardware Requirement
Personal computer.

Theory:
What is Python?
Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming
language. It was created by Guido van Rossum during 1985- 1990. Like Perl, Python source
code is also available under the GNU General Public License (GPL). It has easy syntax
and dynamic semantics. Python is much easier than other programming languages and helps you
create beautiful applications with less effort and much more ease.

Why to Learn Python?


Python is a high-level, interpreted, interactive and object-oriented scripting language. Python is
designed to be highly readable. It uses English keywords frequently where as other languages
use punctuation, and it has fewer syntactical constructions than other languages.

Python is MUST for students and working professionals to become a great Software Engineer
especially when they are working in Web Development Domain. Following are the key
advantages of learning Python:

 High Level

Python derives components from the natural language that we humans use to


communicate with each other. This makes it easier for anyone to try and relate what
exactly could be happening without the burden of going through tons of machine code.

 Interpreted

Python codes are compiled line-by-line which makes debugging errors much easier and
efficient. But this comes at a cost as it is much slower than other programming languages.

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

 Easy Syntax

Python makes use of indentations instead of braces to distinguish what blocks of code


come under which class or function. This makes the code look well distributed and
makes it easy for anyone to read it.

 Dynamic Semantics

If you are an old school coder, you would know that before using anything, you would
need to initialize it. It does all of this dynamically.

 Interactive

You can actually sit at a Python prompt and interact with the interpreter directly to write
your programs.

 Python is Object-Oriented

Python supports Object-Oriented style or technique of programming that encapsulates


code within objects.

 Python is a Beginner's Language

Python is a great language for the beginner-level programmers and supports the
development of a wide range of applications from simple text processing to WWW
browsers to games.

How is Python used?


Understanding what is Python and why it should be used, you would wonder what can you do
when you master it. Well, the list is just surprisingly long. For instance,

 Creating web applications with Python Frameworks such as Django and Flask


 You can create workflows for the software that you are working on
 Use Python to modify files and data stored in Databases
 Scientific, Analytic and complex calculations can be taken care of easily
 You can create software much quicker with Python, which is ready for deployment

The list just goes on and on. You can have a really good career with Python as your go-to
language for solving problems. Let me name a few of the titles that you can pursue.

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

 Data Scientist

A Data Scientist is someone who cracks complex problems which relate to the field of


math, statistics and brings around a solution to these problems in a logical manner.

 Software Engineer

Software engineers design, develop, test and maintain software applications that they
create for their clients according to the requirements. 

 Web Developer

Web developers create web applications to serve their users using the client-
server model. There are applications such as information sharing, social network
platforms, entertainment which are just a few to name.

Python Features
Python is slow. However, its popularity does not stop to grow as it can achieve better
productivity with lesser code, making Python one of the most liked languages. Python has a list
of features that attract almost anyone to start coding with it.

 Simplicity

Python is its own kind of simple. All you need to know is how the indentations work and
you can code the most complex of problems in the fewer lines of code.

 Open Source

Python is free for anyone to use. You even have the freedom to modify the code of
Python to better your own needs without facing any repercussions.

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

 Portability

Code writing can be done once and run across different systems without any changes.
This makes it super helpful when a team works on a project.

 Embedding Properties

Python allows the code of other languages such as C, C++ to be embedded, which makes
it much more powerful and versatile.

 Interpretation

As you know, Python is compiled line-by-line, making debugging easier and memory


management much more efficient

 Library Support

Python supports libraries that you can use and get started off to obtain
your solutions much faster and easier. And the community for these libraries is very
active and helpful

 OOPS

Object-Oriented concepts help you replicate real-world scenarios in your code and also


provide security to them so that you can obtain a well-made application

Getting Started With Python


Starting your journey in Python requires that you are familiar with how the technology actually
works. And the very first thing that you would learn is how you can set up the Python
environment on your systems and choose the best IDE that would help you in the best possible
ways.

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

Python Installation:

To get started working with Python 3, you’ll need to have access to the Python interpreter. There
are several common ways to accomplish this:

 Python can be obtained from the Python Software Foundation website at python.org.
Typically, that involves downloading the appropriate installer for your operating system
and running it on your machine.

 Some operating systems, notably Linux, provide a package manager that can be run to
install Python.

 On macOS, the best way to install Python 3 involves installing a package manager called
Homebrew. You’ll see how to do this in the relevant section in the tutorial.

 On mobile operating systems like Android and iOS, you can install apps that provide a
Python programming environment. This can be a great way to practice your coding skills
on the go.

 Alternatively, there are several websites that allow you to access a Python interpreter
online without installing anything on your computer at all.

 It is highly unlikely that your Windows system shipped with Python already installed.
Windows systems typically do not. Fortunately, installing does not involve much more
than downloading the Python installer from the python.org website and running it. Let’s
take a look at how to install Python 3 on Windows:

Step 1: Download the Python 3 Installer


1. Open a browser window and navigate to the Download page for Windows at python.org.

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

2. Underneath the heading at the top that says Python Releases for Windows, click on the
link for the Latest Python 3 Release - Python 3.x.x. (As of this writing, the latest is
Python 3.6.5.)
3. Scroll to the bottom and select either Windows x86-64 executable installer for 64-bit or
Windows x86 executable installer for 32-bit. (See below.)

Sidebar: 32‐bit or 64‐bit Python?


For Windows, you can choose either the 32-bit or 64-bit installer. Here’s what the difference
between the two comes down to:

• If your system has a 32-bit processor, then you should choose the 32-bit installer.
• On a 64-bit system, either installer will actually work for most purposes. The 32-bit
version will generally use less memory, but the 64-bit version performs better for
applications with intensive computation.
• If you’re unsure which version to pick, go with the 64-bit version.

Note: Remember that if you get this choice “wrong” and would like to switch to another version
of Python, you can just uninstall Python and then re-install it by downloading another installer
from python.org.

Step 2: Run the Installer


Once you have chosen and downloaded an installer, simply run it by double-clicking on the
downloaded file. A dialog should appear that looks something like this:

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

Important: You want to be sure to check the box that says Add Python 3.x to PATH as shown
to ensure that the interpreter will be placed in your execution path.

Then just click Install Now. That should be all there is to it. A few minutes later you should have
a working Python 3 installation on your system.

Python IDEs and Code Editors


A code editor is a tool that is used to write and edit code. They are usually lightweight and can
be great for learning. However, once your program gets larger, you need to test and debug your
code, that's where IDEs come in.

An IDE (Integrated Development Environment) understand your code much better than a text
editor. It usually provides features such as build automation, code linting, testing and debugging.
This can significantly speed up your work. The downside is that IDEs can be complicated to use.
There are number of IDE’s available on internet for it, from which some are defined here:

1. IDLE
When you install Python, IDLE is also installed by default. This makes it easy to get started in
Python. Its major features include the Python shell window (interactive interpreter), auto-
completion, syntax highlighting, smart indentation, and a basic integrated debugger.

IDLE is a decent IDE for learning as it's lightweight and simple to use. However, it's not for
optimum for larger projects.

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

2. Atom
Atom is an open-source code editor developed by Github that can be used for Python
development. It has basic built-in support for Python when you install it. However, you can
install packages such as debugging, auto-completion, code linting, etc.

There are also various packages for scientific development, Django, Flask and so on. Basically,
you can customize Atom to create a full-fledged Python development environment as per your
need. Some of the commonly used packages in Atom for Python development are autocomplete-
python, linter-flake8, python-debugger, etc.

The official website of atom is https://atom.io/ from where you can easily download and install it
for use.

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

3. PyCharm
PyCharm is an IDE for professional developers. It is created by JetBrains, a company known for
creating great software development tools. There are two versions of PyCharm:

1. Community - free open-source version, lightweight, good for Python and scientific
development

2. Professional - paid version, full-featured IDE with support for Web development as well

PyCharm provides all major features that a good IDE should provide: code completion, code
inspections, error-highlighting and fixes, debugging, version control system and code
refactoring. All these features come out of the box.

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

The major disadvantage of PyCharm is that it's resource-intensive. If you have a computer with a
small amount of RAM (usually less than 4 GB), your computer may lag.

The official website of atom is https://www.jetbrains.com/pycharm/download/#section=windows


from where you can easily download and install it for use.

4. Spyder
Spyder is an open-source IDE usually used for scientific development. The easiest way to get up
and running up with Spyder is by installing Anaconda distribution. Anaconda is a popular
distribution for data science and machine learning. The Anaconda distribution includes hundreds
of packages including NumPy, Pandas, scikit-learn, matplotlib and so on.

Spyder has some great features such as autocompletion, debugging and iPython shell. However,
it lacks in features compared to PyCharm.

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

5. Jupyter
Jupyter is a tool for people who have just started with data science. It is easy to use, interactive
data science IDE across many programming languages that just not work as an editor, but also as
an educational tool or presentation.

Features:

 It is one of the best Python IDE that supports for Numerical simulation, data cleaning
machine learning data visualization, and statistical modeling.
 Combine code, text, and images.
 Support for many programming languages.
 Integrated data science libraries (matplotlib, NumPy, Pandas).

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

Installation Process of Anaconda and Jupyter on Windows


1. Go to https://www.anaconda.com/products/individual#windows and Download the
Anaconda installer.
2. RECOMMENDED: Verify data integrity with SHA-256.
3. Double click the installer to launch.
Note
To prevent permission errors, do not launch the installer from the Favorites folder.
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.
4. Click Next.
5. Read the licensing terms and click “I Agree”.
6. Select an install for “Just Me” unless you’re installing for all users (which requires
Windows Administrator privileges) and click Next.
7. Select a destination folder to install Anaconda and click the Next button. See FAQ.
Note
Install Anaconda to a directory path that does not contain spaces or unicode characters.
Note
Do not install as Administrator unless admin privileges are required.

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

8. Choose whether to add Anaconda to your PATH environment variable. We recommend


not adding Anaconda to the PATH environment variable, since this can interfere with
other software. Instead, use Anaconda software by opening Anaconda Navigator or the
Anaconda Prompt from the Start Menu.

9. 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.
10. Click the Install button. If you want to watch the packages Anaconda is installing, click
Show Details.
11. Click the Next button.
12. Optional: To install PyCharm for Anaconda, click on the link
to https://www.anaconda.com/pycharm.

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

Or to install Anaconda without PyCharm, click the Next button.


13. After a successful installation you will see the “Thanks for installing Anaconda” dialog
box:

14. If you wish to read more about Anaconda.org and how to get started with Anaconda,
check the boxes “Anaconda Individual Edition Tutorial” and “Learn more about
Anaconda”. Click the Finish button.
15. Verify your installation.

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

How to launch Jupyter Notebook


There are 3 ways to launch Jupyter Notebook:
1. Using Anaconda Navigator
a. Open the application called Anaconda Navigator (this may take a couple of minutes)
b. Click on “Launch” in the Jupyter Notebook box

2. Using Anaconda Prompt


a) Open the application called Anaconda Prompt
b) Type “jupyter notebook” (without quotes) and hit the return key

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

3. Clicking on the Jupyter Notebook App in the Start Menu (I just learned about this
method, and it will probably be the fastest!)

You will know that Jupyter Notebook opened correctly if you see a page similar to this one open in your
browser!

Navigate through your folders until you get to the directory you want to save your scripts in. You can
navigate through by clicking on the name of the Folder.

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

Open a new Notebook file by clicking on the “New” menu on the upper right.

How to start writing a Jupyter Notebook


A new Notebook looks like this:

First, click on “Untitled” to name your script.

You can add multiple cells in the program and run the code by pressing (Ctrl + Enter).

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

Python print()
The print() function prints the given object to the standard output device (screen) or to the text
stream file.
The full syntax of print() is:
print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)

print() Parameters
 objects - object to the printed. * indicates that there may be more than one object
 sep - objects are separated by sep. Default value: ' '
 end - end is printed at last
 file - must be an object with write(string) method. If omitted it, sys.stdout will be used
which prints objects on the screen.
 flush - If True, the stream is forcibly flushed. Default value: False
Note: sep, end, file, and flush are keyword arguments. If you want to use sep argument, you have
to use:
print(*objects, sep = 'separator')
not
print(*objects, 'separator')

Return Value from print()


It doesn't return any value; returns None.

Example 1: How print() works in Python?


print("Python is fun.")

a=5
# Two objects are passed
print("a =", a)

IQRA University, North Campus, Karachi


FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY

b=a
# Three objects are passed
print('a =', a, '= b')
Output
Python is fun.
a=5
a=5=b

Lab Tasks
1. Install Python using Anaconda and Jupyter Notebook (IDE). (submit three snapshots
showing installation process in your system)
2. Write a program to display your_name, id, department and university name on same line
by a comma separator.
Note: for each information you have to use variable and for each variable you have to use
separate print function.

IQRA University, North Campus, Karachi

You might also like