Installation of Python: Latest Python Version Can Be Downloaded From
Installation of Python: Latest Python Version Can Be Downloaded From
Procedure
It lets the user to write a 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.
It lets the user to write a source code of python program by writing practice programs.
Learning Objectives
1. Printing a Line of Text
2. Comments and new line character
3. Variables
4. Program to find the size of different data types
5. Demonstrating Arithmetic Operators
6. Input statements
7. Type casting
Lab Task 1
iii. “Hello” and “ world” should be displayed on different lines using a single print
statement
2. DATA TYPES
i) Assign a floating value to a variable and then check its type.
ii) Modify the above program by converting the floating type into integer and checks its
type again
iii) Prompt the user to enter a number and save it in an integer variable
1. 6 + 5 * 4 % 3=
2. 12 / 3 * 3 =
3. 10 % 3 – 6 / 2 =
4. 5* * 2 / (4 * 2) =
Complete Programs
2. Assume that there are 7.481 gallons in a cubic foot. Write a program that asks the user to enter
a number of galloons 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
4. 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.
5. 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.
Relational Operators
LAB TASK-2
1. Convert the following expressions to a python expression.
i). If hours is greater than 18, print a message saying "This is an overload"; otherwise
print a message saying "Not an overload".
ii). If classification is equal to 5 then set the character variable Type equal to 'G', and
print a message saying "graduate student"; otherwise set Type equal to 'U' and print a
message saying "undergraduate".
3. Write a program which reads two integer values. If the first is less than the
second, print the message up. If the second is less than the first, print the message
down If the numbers are equal, print the message equal
4. Read 2 numbers and an operator ('+','-','*') display their sum if the user has
entered '+', difference (if the user has entered '-') or the product (if the user has entered
'*')
6. Write a program that determines a student’s grade. The program will read three
scores and determine the grade based on the following rules:
7. Write a python program which when two integers x and y are input will output
the absolute difference of the two integers. That is whichever one of (x-y) or (y-x) is
positive. Think of all the cases that can arise and consequently plan a set of test data
to confirm the correctness of your program.
8.It is decided to base the fine for speeding in a built up area as follows - Rs 500 if
speed is between 31 and 40 mph(inclusive), Rs. 750 if the speed is between 41 and
50 mph(inclusive) and Rs.1000 if he speed is above 50 mph. Write a program to
automate the assessment of a fine(using elseif )
POST LAB
10. Write a python code that prompts the user to input three integer values and
find the greatest value of the three values.
11. You are given a task of writing a program that figures interest on money that is
held in a bank. The amount of interest that money earns in this bank depends on
which type of account the money is in. There are 6 different types of accounts and
they earn interest as follows: