Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
74 views7 pages

ICT1011 - Lab Manual 4

The document discusses control flow statements in Python, specifically if-else and nested if statements. It provides syntax examples and practice problems to write programs that take user input for temperature or age and output a message based on conditional logic.

Uploaded by

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

ICT1011 - Lab Manual 4

The document discusses control flow statements in Python, specifically if-else and nested if statements. It provides syntax examples and practice problems to write programs that take user input for temperature or age and output a message based on conditional logic.

Uploaded by

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

ABU DHABI POLYTECHNIC

Academic Support Department

Laboratory Manual No. 4

Basic Concept and Syntax of Python Programming


(CONTROL FLOW STATEMENTS – Decision Statements)
(if…elif…else, Nested if)

A.C. 2023-2024
ICT-1011: Introduction to Programming and Problem Solving

CONTROL STATEMENT – IF STATEMENT

1. if…elif…else
Syntax:
if Boolean_Expression_1:
statement_1
elif Boolean_Expression_2:
statement_2
elif Boolean_Expression_3:
statement_3
:
:
:
else:
statement_last

2. nested if
Syntax:
if Boolean_Expression_1:
if Boolean_Expression_2:
statement_1
else:
statement_2
else:
statement_3

PRACTICE:

Write a program that will read the temperature of water. Output the corresponding message
based from the condition below.

Temperature Message
Over 100 HOT
From 0 to 100 LUKEWARM
Below 0 COLD

Lab Manual No. 4| Page 2


ICT-1011: Introduction to Programming and Problem Solving

temp=int(input("Enter WATER TEMPERATURE: "))

if temp>100:
print("HOT")
elif (temp>=0) and (temp<=100):
print("LUKEWARM")
elif (temp<0):
print("COLD")

temp=int(input("Enter WATER TEMPERATURE: "))

if temp>100:
print("HOT")
elif (temp>=0) and (temp<=100):
print("LUKEWARM")
else:
print("COLD")

temp=int(input("Enter WATER TEMPERATURE: "))

if temp>100:
print("HOT")
elif (temp>=0):
print("LUKEWARM")
else:
print("COLD")

Name: _________________________ ID: ______________


Reserved Section
Lab: _____________________________ Grade:

Date: __________________________ CRN: ______________

LABORATORY EXERCISES:

Lab Manual No. 4| Page 3


ICT-1011: Introduction to Programming and Problem Solving

Task 1
ABC Company decided to increase the salary of their employees based on the number of years
in service. Write a program using if…elif…else statement that will ask the user to input their
current salary and number of years in service. Compute and output the increase in salary and
the new salary as per the list below

Number of Years in Service Percent of increase


More than 10 years 10 percent
5 years to 10 years 5 percent
2 years to 4 years 3 percent
Less than 2 years 1 percent

Task 1 Answer (Screenshot + program code)


# Get user input for current salary and years in service
current_salary = float(input("Enter your current salary: $"))
years_in_service = int(input("Enter the number of years in service: "))

# Define the initial percent increase and then update it based on years in service
percent_increase = 0

if years_in_service > 10:

Lab Manual No. 4| Page 4


ICT-1011: Introduction to Programming and Problem Solving

percent_increase = 10
elif years_in_service >= 5:
percent_increase = 5
elif years_in_service >= 2:
percent_increase = 3
else:
percent_increase = 1

# Calculate the increase in salary and the new salary


increase = (percent_increase / 100) * current_salary
new_salary = current_salary + increase

# Display the results


print(f"Based on {years_in_service} years in service, you will receive a {percent_increase}% salary
increase.")
print(f"Your new salary will be: ${new_salary:.2f}")

Lab Manual No. 4| Page 5


ICT-1011: Introduction to Programming and Problem Solving

Task 2
write a program using a Nested if statement that will ask for your age. You're not eligible to
buy a ticket if you’re less than 18 years old. If you’re less than 21 years or greater than 65 years,
your ticket is $15, otherwise it is $30.

Task 2 Answer (Screenshot + program code)

# Get user input for age


age = int(input("Enter your age: "))

# Check if the person is eligible to buy a ticket


if age < 18:
print("You are not eligible to buy a ticket.")
else:
if age < 21 or age > 65:
ticket_price = 15
else:
ticket_price = 30

print(f"Your ticket price is ${ticket_price}.")

Lab Manual No. 4| Page 6


ICT-1011: Introduction to Programming and Problem Solving

Lab Manual No. 4| Page 7

You might also like