Professional Documents
Culture Documents
Introduction
If/else statement is a basic decision making statement in programming. It executes one block of
statements when the condition is true and other when it is false. In any situation, one block is
executed and other is skipped.
Objectives
The objective of this lab is to understand if/else statement
Tools/Software Requirement
Python IDLE
Description
== equal to 5 == 5 is TRUE
Syntax:
if(Condition):
Statement
else:
Statement
Lab Tasks:
Using only the programming techniques that you have learned so far, perform the
following tasks:
Note: All the tasks of this lab should be performed in Python scripted mode only.
1. Write a program that reads an integer and determines and prints whether it is odd or even.
[1
Mark]
Task 1 Snap
#Add here the snap showing your Python code and the required output.
2. Write a program that inputs three different integers from the keyboard, and then prints the
smallest and the largest of these numbers. Use only the single-selection form of the if
statement that you learned in the class. The screen dialogue should appear as follows:
Hint: You can use split() function in combination with input() function to take multiple
input values from user in a single line.
[1
Mark]
Task 2 Snap
#Add here the snap showing your Python code and the required output.
3. Modify above program to read in five integers and then determine and print the largest
and the smallest integers in the group.
[1
Mark]
Task 3 Snap
#Add here the snap showing your Python code and the required output.
4. Write a program that reads three nonzero integers and determines and prints if they could
be the sides of a right triangle.
[1
Mark]
Task 4 Snap
#Add here the snap showing your Python code and the required output.
5. A palindrome is a number or a text phrase that reads the same backwards as forwards.
For example, each of the following five-digit integers are palindromes: 12321, 55555,
45554 and 11611. Write a program that reads in a five-digit integer and determines
whether or not it is a palindrome.
Help resource: String slicing , indexing and striding
[2
Marks]
Task 5 Snap
#Add here the snap showing your Python code and the required output.
6. Write a program that takes as input a letter and displays if it is a vowel using conditional
statements. [2 Marks]
Task 6 Snap
#Add here the snap showing your Python code and the required output.
7. Write a program to calculate energy bill using conditional statements. Read the starting and
ending meter reading. The charges are as follows:
[2 Marks]
Task 7 Snap
#Add here the snap showing your Python code and the required output.
Deliverables
Compile a single Word document by filling in the solution/answer part (as directed) along with
the snapshots. Name your submission file as given below and submit this Word file on LMS
before the deadline.
Grade Criteria
This lab is graded. Min marks: 0. Max marks: 10.
Activity Minimum Maximum
Documentation with clearly defined Fail Pass
understanding of the lab task and approach
Task 1 0 01
Task 2 0 01
Task 3 0 01
Task 4 0 01
Task 5 0 02
Task 6 0 02
Task 7 0 02