0% found this document useful (0 votes)
3 views5 pages

CSE1500 - Computational Thinking Using Python Labsheet 2.1

The document outlines several programming problems related to automation in various domains, including an electricity billing system, a college placement eligibility system, a Kaprekar constant calculation, and a prime number generator for OTPs. Each problem includes a detailed problem statement and corresponding Python code to implement the solution. Additionally, there are student activities suggested for further practice and exploration of the concepts presented.

Uploaded by

spashpicasso
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)
3 views5 pages

CSE1500 - Computational Thinking Using Python Labsheet 2.1

The document outlines several programming problems related to automation in various domains, including an electricity billing system, a college placement eligibility system, a Kaprekar constant calculation, and a prime number generator for OTPs. Each problem includes a detailed problem statement and corresponding Python code to implement the solution. Additionally, there are student activities suggested for further practice and exploration of the concepts presented.

Uploaded by

spashpicasso
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

Computational Thinking Using Python – CSE1500

Lab sheet – 2.1

1) Problem Statement:

Rakesh is working as a Manager at BESCOM (a power distribution company). He


wants to automate the billing system for different categories of consumers.

The company provides electricity to three categories of consumers:

1. Domestic Users

 First 100 units → ₹3 per unit


 Next 100 units (101–200) → ₹5 per unit
 Above 200 units → ₹8 per unit
 Service charge → ₹50

2. Commercial Users

 First 300 units → ₹6 per unit


 Next 300 units (301–600) → ₹8 per unit
 Above 600 units → ₹12 per unit
 Service charge → ₹200

3. Industrial Users

 First 500 units → ₹9 per unit


 Next 500 units (501–1000) → ₹15 per unit
 Above 1000 units → ₹20 per unit
 Service charge → ₹1000

Develop a suitable python application to calculate the final bill payable by the user.
Python Code:
# Electricity Billing System using match-case
units = int(input("Enter units consumed: "))
print("enter consumer category Domestic or Commercial or Industrial")
category = input().lower() # convert to lowercase for consistency
match category:
case "domestic": # Domestic Users
if units <= 100:
bill = units * 3
elif units <= 200:
bill = (100 * 3) + (units - 100) * 5
else:
bill = (100 * 3) + (100 * 5) + (units - 200) * 8
total_bill = bill + 50 # service charge
print("total bill is",total_bill)
case "commercial": # for commercial users
if units <= 300:
bill = units * 6
elif units <= 600:
bill = (300 * 6) + (units - 300) * 8
else:
bill = (300 * 6) + (300 * 8) + (units - 600) * 12
total_bill = bill + 200 # service charge
print("total bill is",total_bill)
case "industrial": # for Industrial Users
if units <= 500:
bill = units * 9
elif units <= 1000:
bill = (500 * 9) + (units - 500) * 15
else:
bill = (500 * 9) + (500 * 15) + (units - 1000) * 20
total_bill = bill + 1000 # service charge
print("total bill is",total_bill)
case _: print("invalid category")
===============================

2 ) Problem Statement:

A college wants to automate its Placement Training and Field Visit Eligibility System.
 Rule 1: If a student is in semester 1, 3, 5, or 7 and the branch is CSE, then the
student is eligible for placement training.
 Rule 1: If a student is in semester 1, 3, 5, or 7 and the branch is AIML, then the
student is eligible for AI training.
 Rule 3: If a student is in semester 2, 4, or 6 and the branch is CIVIL, then the
student is eligible to go for a field visit.
 Rule 4: If a student is in semester 2, 4, or 6 and the branch is ECE, then the
student is eligible to go for a electronics company visit
 For all other cases, display “Eligibility criteria”

Python Code:

sem=int(input("enter semester"))
branch=input("enter any branch such as CSE or CIVIL").upper()
match sem:
case 1 | 3 | 5 | 7 if branch == "CSE":
print("student is eligible for placement training")
case 1 | 3 | 5 | 7 if branch == "AIML":
print("student is eligible for AI training")
case 2 | 4 | 6 if branch == "CIVIL":
print("student is eligible for field visit")
case 2 | 4 | 6 if branch == "ECE":
print("student is eligible for electronics company visit")
case _:
print("Eligibility criteria not defined for this case")
===========================

3 ) Problem Statement:

Kaprekar, an Indian Mathematician, discovered many patterns in numbers, a special


routine for 4-digit numbers known as the Kaprekar Constant.
 Take a 4-digit number (digits must be in descending order) For example: 8765,
let it be ‘a’
 Find smallest number from the above digits (say for example 6578), let it be ‘b’
 Subtract b from a, call it c. for example c = a – b
Develop python code to solve the above problem.
a=int(input("enter any four digit number in which digits must be in order "))
# find smallest of a or reverse
x=a
rev=0
while x!=0 :
r=x%10
rev=rev*10+r
x=x//10
b=rev
c=a-b
print("a value is ",a)
print("b value is ",b)
print("kaprekar constant is ",c)

Note : Again enter the result as input to the above program until you reach the
magic number “6174”, which is known as ‘Kaprekar Constant’.

Student activity : Rewrite the above logic to stop once if you reach Kaprekar
Constant.
=====================

4 ) Problem Statement:

Rahul is a General Manager in HDFC bank. Banks generate secure one-time


passwords (OTPs) for online transactions. Hackers may guess weakly generated
OTPs. Large primes are used in OTP algorithms for secure and unpredictable
generation. Help Rahul to develop a python application to generate prime number in
a range.
import math
# Optimized Prime Number Check
num = int(input("Enter a number: "))
is_prime = True
for i in range(2, int([Link](num)) + 1):
if num % i == 0:
is_prime = False
break
if is_prime:
print(num, "is a prime number")
else:
print(num, "is not a prime number")

Student Activity : Using above logic print / generate prime numbers from 100 to
200. (range)
“There are several methods to check whether a number is prime or not; the one above is
the most efficient solution.”
=============================

You might also like