0% found this document useful (0 votes)
70 views

Installation of Python: Latest Python Version Can Be Downloaded From

The document provides instructions for installing Python and introduces programming concepts in Python like data types, arithmetic operators, input/output statements, and conditional statements. It includes examples of writing simple Python programs to print text, perform calculations, take user input, and make conditional checks. Lab tasks are provided to have students write Python code to demonstrate their understanding of these basic programming concepts.

Uploaded by

ALvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views

Installation of Python: Latest Python Version Can Be Downloaded From

The document provides instructions for installing Python and introduces programming concepts in Python like data types, arithmetic operators, input/output statements, and conditional statements. It includes examples of writing simple Python programs to print text, perform calculations, take user input, and make conditional checks. Lab tasks are provided to have students write Python code to demonstrate their understanding of these basic programming concepts.

Uploaded by

ALvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Installation of Python

Latest python version can be downloaded from


https://www.python.org/downloads/windows/

Introduction to Programming environment in Python


Objective
To acquaint the students with IDLE for Python programming.

To write a simple program

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.

3. Write the source code as follows and save the file.


4. Save the program with the extension .py.

5. Program must be saved every time before executing.


6. Short hand for running a program is fn+f5 or Run option can be chosen
7. If the program runs successfully, output will be shown in the shell otherwise an
error window will be displayed.

Writing a simple Program

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

1. Write a python code for the following

i. displays the statement “Hello world!”


ii. “Hello” and “ world” should be displayed on different lines using multiple print
statements

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

4.What does the following expression evaluate to?

1. 6 + 5 * 4 % 3=
2. 12 / 3 * 3 =
3. 10 % 3 – 6 / 2 =
4. 5* * 2 / (4 * 2) =

Complete Programs

1. Write a program which inputs a temperature reading expressed in Fahrenheit and


outputs its equivalent in Celsius, using the formula:
C = 5/9(F- 32)
Compile and run the program. Its behavior should resemble this:
Temperature in Fahrenheit: 41
41 degrees Fahrenheit = 5 degrees Celsius

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.weight is greater than 100


ii. a is between 0 and 100 inclusive
iii. answer is neither 'Y' nor 'y'

2. Write a python statement

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
'*')

5. Read the two numbers val1 ,val2.


If val1 is greater, calculate
val1-val2
else if val2 is greater, calculate
val2-val1
else if both are equal, calculate
val1+val2

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:

-if the average score =90% =>grade=A


-if the average score >= 70% and <90% => grade=B
-if the average score>=50% and <70% =>grade=C
-if the average score<50% =>grade=F

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

9. Write a python program which will compute the area of a square (


base * hieght
) or a triangle ( area = ) after prompting the user to
2
type the first character of the figure name (t or s).

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:

account type interest earned

personal financial 2.3%

personal homeowner 2.6%

personal gold 2.9%

small business 3.3%

big business 3.5%

gold business 3.8%


[Hint: Assuming also that you have assigned numbers to the account types starting
with personal financial and ending with gold business]. Also give reason of why using
switch statement is more appropriate in this problem?

You might also like