Programming Lab Report 6 (Conditional Statements) .... Syed Fasih - Institute of Space & Technology
Programming Lab Report 6 (Conditional Statements) .... Syed Fasih - Institute of Space & Technology
Marks Obtained
NAME Syed Fasih Abbas
REGISTRATION # 220701054
LAB REPORT 6
PERFORMANCE
TOTAL MARKS
Objectives:
The objective of this lab is to teach the student how to use ‘if’ statements & its various
formats.
After this lab the students will be able to understand the importance and use of ‘if’ statements
To evaluate various conditions and execute statements or a group of statements depending on
whether the condition was True or False.
Introduction:
‘if’ statement is used to perform logical operation. In order to perform decision making,
we need to check certain condition before processing. Python supports if statement for
doing so. There are various formats of if statement including if-else and if-elif.
The basic and shortest form of if statement is as below:
if condition:
statement1
statement2
…
If the condition is true then the specified block will
be executed. It is important to note
if condition:
statement1
statement2
…
else:
statement3
statement4
…
If we are required to test a number of conditions and
want to execute one of the many
Statement5
Statement6
else:
Statement7
Statement8
Lab Tasks
Task 1
Write a program that accepts two values from the user and compares both
values. The program displays “Both are equal” if the values are equal, or
“The first value is greater than second” or “The second value is greater
than the first” if user has entered so.
y is greater than x
Task 2
Write a Python code to accept marks of a student from 1-100 and display
the grade according to the following formula.
Grade F if marks are less than 50, Grade E if marks are between 50 to 60,
Grade D if marks are between 61 to 70, Grade C if marks are between 71 to
80, Grade B if marks are between 81 to 90, and Grade A if marks are
between 91 to 100.
Input Output
73 Grade C
59 Grade E
Introduction to IT Lab Page 4 Experiment # 6
Page 5 of 6
Task 3
Write a Python code to accept temperature value from user (in centigrade)
and display an appropriate message as below.