0% found this document useful (0 votes)
31 views8 pages

CLO3-Part2-Lab - Solutio

This document contains instructions for 5 coding exercises that involve using nested if statements in Python. The exercises involve calculating delivery charges, service charges, ticket prices with discounts, adding suffixes to numbers, and finding the tallest height among 3 people. Sample code is provided for each exercise. The document also references a case study that will be included in all course activities.

Uploaded by

4tbvy4hr65
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)
31 views8 pages

CLO3-Part2-Lab - Solutio

This document contains instructions for 5 coding exercises that involve using nested if statements in Python. The exercises involve calculating delivery charges, service charges, ticket prices with discounts, adding suffixes to numbers, and finding the tallest height among 3 people. Sample code is provided for each exercise. The document also references a case study that will be included in all course activities.

Uploaded by

4tbvy4hr65
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/ 8

ICT 2013: COMPUTATIONAL

THINKING & CODING

ACTIVITY CLO3_2

COURSE LEARNING OUTCOME: CLO3

CHAPTERS:

COGNITIVE LEVELS: APPLY

AIM: USE SELECTION WITH NESTED IF STATEMENTS

TOOLS: PYTHON/REPL.IT

PROCEDURE:

DOCUMENT REVISION CONTROL:1.0

Version Author Effective Date Change Description DCR No

1.0 Dr Madeleine Togher 1.0


1.1 Anand Pandiyan 29.09.2021 Added 2 more task.

1
EXERCISE 1-APPLY

The appliances section in Carrefour add a delivery charge (per items) onto the appliances bill
as follows:

Items Additional
delivery charge
per item
Up to 2 70
3 to 5 50
6 to 7 35
More than 7 30

Write a python program that asks the user to enter the number of items then calculates and
displays the total delivery charge that the client will need to pay.

Solution

Model answer

Items = int(input("Enter the number of items: "))


Charge=0

if (Items<1):
print ("Error, Items must be 1 and above !!")
elif (Items < 3):
Charge = Charge + (Items * 70)
elif (Items < 6):
Charge = Charge + (Items * 50)
elif (Items < 8):
Charge = Charge + (Items * 35)
else:
Charge = Charge + (Items * 30)

print ("Delivery charges is " , Charge)

2
EXERCISE 2 - APPLY

Write a program to read the number of computers that need to service and calculate the
service charge as in below table. See screen shot below.

PCs Charges / per pc


Up to 3 100
4-6 75
7-9 50
>10 40

Screenshot

Solution

PCs_Number = int(input("Enter number of PCs you need servces "))

charge=0

if (PCs_Number>=1 and PCs_Number<4):


charge = PCs_Number * 100
elif (PCs_Number < 7):
charge = PCs_Number * 75
elif (PCs_Number < 10):
charge = PCs_Number * 50
else:
charge = PCs_Number * 40

print("The service charge is ", charge)

3
EXERCISE 3 - APPLY

AD parks sell entry ticket at the cost of dirhams 200. They give discount based on number of
tickets bought as shown in below table.

Number of tickets Discount


1–3 0
4–6 5%
7 – 10 8%
Above 10 12%

Write a Python program that read number of ticket purchased, calculate and display the total
price before the discount, discount amount and final price after discount.

Screenshot

Solution

tickets = int(input("Enter number of tickets purchased "))

charge = 200 * tickets

if (tickets >=1 and tickets <=3):


rate = 0
discount = charge * 0
elif (tickets >=4 and tickets <=6):
rate = 5
discount = charge * 0.05
elif (tickets >=7 and tickets <=10):
rate = 8
discount = charge * 0.08
else:
rate = 12
discount = charge * 0.12
discounted_price = charge - discount

4
print("Total amount before discount is", charge)
print("Discount at", rate, "% is", discount)
print("Final price after discount is", discounted_price)

EXERCISE 4 - APPLY

Write a Python program that read number and display the number with the suffix based on
the last digit of the number as shown below.

Last digit of number Suffix


1 st
2 nd
3 rd
4,5,6,7,8,9,0 th

Screenshot-1 Screenshot-2 Screenshot-3

Note: You can use modules operator to get the last digit of a number.
Solution

n = int(input("Enter a number "))

last_digit = n % 10

if (last_digit == 1):
print(n, "-st")
elif (last_digit == 2):
print(n, "-nd")
elif (last_digit == 3):
print(n, "-rd")
else:
print(n, "-th")

5
EXERCISE 5 - APPLY

Write a program to read the heights of 3 persons, then find and display the tallest height. See
screen shot below.

Screenshot

Solution

6
height1= float(input("Enter the first person height: "))
height2= float(input("Enter the second person height: "))
height3= float(input("Enter the third person height: "))

max=0
if (height1>height2):
if (height1>height3):
max =height1
else:
max =height3
else:
if (height2>height3):
max =height2
else:
max =height3

print ("The tallest of all the three is ", max)

CASE STUDY-COGNITIVE LEVEL

THIS CASE STUDY IS EXTRACTED FROM XXXX.

IT WILL BE INCLUDED IN ALL COURSE ACTIVITIES.

STUDENTS ARE INVITED TO WORK IN GROUP TO ANSWER


ALL QUESTIONS.

AUTHOR

AIM

CASE DESCRIPTION

7
QUESTIONS
1. Question 1 description
2. Question 1 description
3. Question 3 description
4. Question 4 description
5. Question 5 description
6. Question 6 description

Green color means these questions were solved in the previous activities
Black color indicates that the question be will treated in the current activity
Gray color means that these questions will be investigated during the upcoming activities

You might also like