Lab 01
Lab 01
Lab 01
Objectives
• IDLE
• PyCharm
• Spyder
• Thonny
• Atom
• PyDev
• Visual Studio Code
• Sublime Text
• Wing IDE
• Visual Studio
• Pyscripter
• Jupyter
Basic Structure
Python is a high-level, interpreted programming language that is easy to learn and use. It has a simple and
easy-to-understand syntax that emphasizes readability and reduces the cost of program maintenance. There
is no use of curly braces or semicolon in Python programming language. It is English-like language. But
Python uses the indentation to define a block of code. Indentation is nothing but adding whitespace before
the statement when it is needed. The basic structure of a Python program consists of the following
components:
1. Comments: Comments are used to explain the purpose of the code or to make notes for other
programmers. They start with a ‘#’ symbol and are ignored by the interpreter.
2. Import Statements: Import statements are used to import modules or libraries into the program.
These modules contain predefined functions that can be used to accomplish tasks.
3. Variables: Variables are used to store data in memory for later use. In Python, variables do not
4. Data Types: Python supports several built-in data types including integers, floats, strings,
5. Operators: Operators are used to perform operations on variables and data. Python supports
6. Control Structures: Control structures are used to control the flow of a program. Python supports
7. Functions: Functions are used to group a set of related statements together and give them a name.
8. Classes: Classes are used to define objects that have specific attributes and methods. They are used
9. Exceptions: Exceptions are used to handle errors that may occur during the execution of a program.
Overall, the basic structure of a Python program consists of these components working together to
accomplish a specific task or solve a particular problem.
Procedure
It lets the user write source code of Python program by following these steps.
1. Click on File on the shell and from the drop-down list select New File.
2. The following window will appear, choose file -> new to create a new .py file.
3. Write the source code as follows and save the file.
# This is a comment
# Defining variables
x = 10
y = "Hello, World!"
z = True
# Defining a function
def greet(name):
print("Hello, " + name + "!")
Data types
Python has the following data types of built-in by default, in these categories:
x=10
Print(type(x))
Practice
Try it
Import random
Print(random.randrange(1,10))
Print(“/n”*100)
2. DATA TYPES
a. Assign a floating value to a variable and then check its type.
b. Modify the above program by converting the floating type into integer and checks its type
again.
c. Prompt the user to enter a number and save it in an integer variable.
Complete Programs
2. Assume that there are 7.481 gallons in a cubic foot. Write a program that asks the user to enter several
gallons and then displays the equivalent in the cubic foot.
3. Write a program that asks for your height in integer inches and then convert your height into feet and inches
POST LAB
1.Write a program that requests the user to enter the current world population and the current
population of the U.S. (or of some other nation of your choice). Store the information in
variables of type int. Have the program display the percent that the U.S. (or other nation’s)
population is of the world’s population. The output should look something like this:
Enter the world's population: 6888
Enter the population of the US: 310
The population of the US is 4.5% of the world population.
2. Write a program that asks how many miles you have driven and how many gallons of gasoline
you have used and then reports the miles per gallon your car has gotten. The program can request
distance in kilometers and petrol in liters and then report the result in liters per 100 kilometers.
3. A palindrome is a word, phrase, or sequence of numbers that read the same backward as forward.
Write a program which detects if input sequence is palindrome or not.