Py
Py
def main():
word=input("Enter the word: ")
word = word.lower()
result = is_palindrome(word)
if result == 1:
print("The given word is a Palindrome")
else:
print("The given word is not a Palindrome")
main()
OUTPUT:
Enter the word: click
The given word is not a Palindrome
---------------------------------------------------------------------------------------------------------------'''
def find_ten_substring(num_str):
str1 = ""
list1 = []
a=0
for i in range(0, len(num_str)):
a = a + int(num_str[i])
str1 += str(num_str[i])
if (a == 10):
a=0
list1.append(str1)
str1 = ""
return (list1)
num_str = "2825302"
print("The number is:", num_str)
result_list = find_ten_substring(num_str)
print(result_list)
OUTPUT:
['352']
'''--------------------------------------------------------------------------------------------------------------
Register Number – 191805
Date – 04/12/2019
Program no – 34
Given a number n, write a program to find the sum of the largest prime factors of each of nine
consecutive numbers starting from n.
g(n) = f(n) + f(n+1) + f(n+2) + f(n+3) + f(n+4) + f(n+5) + f(n+6) + f(n+7) + f(n+8)
where, g(n) is the sum and f(n) is the largest prime factor of n.
---------------------------------------------------------------------------------------------------------------'''
def largest_prime(n):
# list to store prime nunumber
prime_list = []
def main():
n = int(input("Enter a number: "))
sum_of_prime = 0
# nine consecutive 0 to 8
for num in range(n, n + 9):
sum_of_prime += largest_prime(num)
print(sum_of_prime)
main()
OUTPUT:
Enter a number: 15
92
'''--------------------------------------------------------------------------------------------------------------
Register Number – 191805
Date – 04/12/2019
Program no – 35
Write a python function find_smallest_number() which accepts a number n and returns the
smallest number having n divisors.
Handle the possible errors in the code written inside the function.
def main():
num=int(input("Enter the number: "))
print("The number of divisors :", num)
result = find_smallest_number(num)
print("The smallest number having", num, " divisors:", result)
main()
OUTPUT:
Enter the number: 45
The number of divisors : 45
The smallest number having 45 divisors: 3600
def main():
list_of_numbers = [1, 6, 6, 3, 7, 3, 4, 2, 4, 4]
list_of_duplicates = find_duplicates(list_of_numbers)
print(list_of_duplicates)
main()
OUTPUT:
[3, 4, 6]
'''--------------------------------------------------------------------------------------------------------------
Register Number – 191805
Date – 04/12/2019
Program no – 37
Write a python function, nearest_palindrome() which accepts a number and returns the
nearest palindrome greater than the given number.
---------------------------------------------------------------------------------------------------------------'''
def nearest_palindrome(number):
if number == 0:
return
else:
flag = 0
while flag != 1:
temp_num = number
new_num = 0
rem = 0
while temp_num != 0:
rem = temp_num % 10
new_num = new_num * 10 + rem
temp_num = temp_num // 10
if new_num == number:
flag = 1
else:
number = number + 1
return new_num
def main():
number=int(input("Enter the number: "))
print(nearest_palindrome(number))
main()
OUTPUT:
Enter the number: 32
33
Note:
1. Assume that the sentence would begin with a word and there will be only a
single space between the words.
2. Perform case sensitive string operations wherever necessary.
def main():
sentence = "life is not easy".lower()
encrypted_sentence_list = encrypt_sentence(sentence)
for i in encrypted_sentence_list:
print(i, end=' ')
main()
OUTPUT:
def main():
head_count = tail_count = 0
for i in range(0, 1000):
if random.randint(1, 10) > 3:
head_count += 1
else:
tail_count += 1
print("Total number of times head occurs: ", head_count)
print("Total number of times tail occurs: ", tail_count)
main()
OUTPUT:
Note: Assume that the sentence would begin with a word and there will be
only a single space between the words.
Sample Input Expected Output
I love Python I lv Pythn
MSD says I love cricket and MSD sys I lv crckt nd tnns t
tennis too
I will not repeat mistakes I wll nt rpt mstks
---------------------------------------------------------------------------------------------------------------'''
def sms_encoding(sentence):
vowels = ['a', 'e', 'i', 'o', 'u']
for word in sentence.split(' '):
converted_word = ''
for letter in word:
if letter not in vowels:
converted_word += letter
if converted_word != '':
print(converted_word, end=' ')
else:
print(word, end=' ')
def main():
sentence = input('Enter sentence to be converted: ')
sentence=sentsce.lower()
sms_encoding(sentence)
main()
OUTPUT:
Enter sentence to be converted: I love Python
I lv Pythn
'''--------------------------------------------------------------------------------------------------------------
Register Number – 191805
Date – 04/12/2019
Program no – 42
Create two functions: odd() and even()
The function even() returns a list of all the even numbers from sample_data
The function odd() returns a list of all the odd numbers from sample_data
Create a function sum_of_numbers() which will accept the sample data and/or
a function.
If a function is not passed, the sum_of_numbers() should return the sum of all
the numbers from sample_data
If a function is passed, the sum_of_numbers() should return the sum of
numbers returned from the function passed.
---------------------------------------------------------------------------------------------------------------'''
def sum_of_numbers(list_of_num, filter_func=None):
num_sum = 0
if filter_func is None:
for i in list_of_num:
num_sum = num_sum + i
print("Even Numbers:", even(list_of_num))
print("Odd Numbers:", odd(list_of_num))
return num_sum
else:
return filter_func(list_of_num)
def calulate_sum(data):
num_sum = 0
for i in data:
num_sum = num_sum + i
return num_sum
def even(data):
even_list = list()
for i in data:
if i % 2 == 0:
even_list.append(i)
return even_list
def odd(data):
odd_list = list()
for i in data:
if i % 2 != 0:
odd_list.append(i)
return odd_list
def even(data):
total = 0
for i in data:
if i % 2 == 0:
total += i
return total
def odd(data):
total = 0
for i in data:
if i % 2 != 0:
total += i
return total
def main():
sample_data = range(1, 11)
print("Total: ", sum_of_numbers(sample_data,None))
print("Even Total: ", sum_of_numbers(sample_data, even(sample_data)))
print("Odd Total: ", sum_of_numbers(sample_data, odd(sample_data)))
main()
OUTPUT:
def main():
poem = '''
If I can stop one heart from breaking,
I shall not live in vain;
If I can ease one life the aching,
Or cool one pain,
Or help one fainting robin
Unto his nest again,
I shall not live in vain.
'''
print(len(re.findall("v", poem)))
print(re.sub(r"\n", "", poem))
temp_poem = re.sub('ch', 'Ch', poem)
print(re.sub('co', 'Co', temp_poem))
print(re.sub(r'(ai|hi)(...)', r'\1*\*', poem))
main()
OUTPUT
4
If I can stop one heart from breaking, I shall not live in vain; If I can ease one life the
aching, Or cool one pain, Or help one fainting robin Unto his nest again, I shall not
live in vain.
def main():
str1=input("Enter the 1st string: ")
str2=input("Enter 2nd string: ")
print(check_anagram(str1, str2))
main()
OUTPUT:
# Global variable
ticket_list = ["AI567:MUM:LON:014", "AI077:MUM:LON:056",
"BA896:MUM:LON:067", "SI267:MUM:SIN:145",
"AI077:MUM:CAN:060", "SI267:BLR:MUM:148",
"AI567:CHE:SIN:015", "AI077:MUM:SIN:050",
"AI077:MUM:LON:051", "SI267:MUM:SIN:146"]
def find_passengers_flight(airline_name="AI"):
count = 0
for item in ticket_list:
data = item.split(":")
if re.search('^'+airline_name, data[0]):
count += 1
return count
def find_passengers_destination(destination):
count = 0
for item in ticket_list:
data = item.split(":")
if destination == data[2]:
count += 1
return count
def find_passengers_per_flight():
flights = list()
for i in ticket_list:
flights.append(i.split(':')[0])
unique_flights = set(flights)
result_list = list()
for i in unique_flights:
count = 0
for j in flights:
if i == j:
count += 1
result_list.append(i + ':' + str(count))
return result_list
def sort_passenger_list():
passengers_per_flight = find_passengers_per_flight()
for i in range(0, len(passengers_per_flight) - 1):
for j in range(i+1, len(passengers_per_flight)):
if passengers_per_flight[i].split(':')[1] > passengers_per_flight[j].split(':')[1]:
passengers_per_flight[i], passengers_per_flight[j] = passengers_per_flight[j],
passengers_per_flight[i]
return passengers_per_flight
def main():
# Provide different values for airline_name and destination and test your program.
airline_name = input("Enter Flight Name: ").upper()
print("Number of passengers flying :", find_passengers_flight(airline_name))
main()
OUTPUT
max_freq = 0
for i in dict_word_freq:
if dict_word_freq[i] > max_freq:
max_freq = dict_word_freq[i]
for word, frequency in dict_word_freq.items():
if frequency == max_freq:
print(word, frequency)
data = " Courage is not the absence of fear but rather the judgement that something else is
more important than fear "
max_frequency_word_counter(data.lower())
OUTPUT:
fear 2
'''--------------------------------------------------------------------------------------------------------------
Register Number – 191805
Date – 04/12/2019
Program no – 47
Write a python program to find and display the number of circular primes less than the given
limit.
---------------------------------------------------------------------------------------------------------------'''
def prime(number):
return number > 1 and all(number % i != 0 for i in range(2, number))
def rotations(num):
rotated = []
m = str(num)
for _ in m:
rotated.append(int(m))
m = m[1:] + m[0]
return rotated
def prime_count(limit):
counter = 0
return counter
print(prime_count(480))
OUTPUT:
20
'''--------------------------------------------------------------------------------------------------------------
Register Number – 191805
Date – 04/12/2019
Program no – 48
Write a function, validate_credit_card_number(), which accepts a 16 digit credit card number
and returns true if it is valid as per Luhn’s algorithm or false, if it is invalid. Also write the
pytest test cases to test the program.
---------------------------------------------------------------------------------------------------------------'''
def validate_credit_card_number(card_number):
odd_pos_num = 0
even_pos_num = 0
temp_num = card_number
flag = 0
while temp_num != 0:
flag = flag + 1
rem = temp_num % 10
temp_num = temp_num // 10
if flag % 2 != 0:
even_pos_num = even_pos_num * 10 + rem
else:
odd_pos_num = odd_pos_num * 10 + rem
temp_num = odd_pos_num
odd_sum = 0
while temp_num != 0:
rem = temp_num % 10
temp_num = temp_num // 10
rem = rem * 2
if rem > 9:
rem = (rem % 10) +(rem // 10)
odd_sum = odd_sum + rem
temp_num = even_pos_num
while temp_num != 0:
rem = temp_num % 10
temp_num = temp_num // 10
odd_sum = odd_sum + rem
if odd_sum % 10 == 0:
return True
else:
return False
def check_perfectno_from_list(no_list):
perfect_num_list = list()
for num in no_list:
if check_perfect_number(num):
perfect_num_list.append(num)
return perfect_num_list
print(remove_duplicates(""227700448833asd&7**SS""))
OUTPUT:
270483asd&*S
'''--------------------------------------------------------------------------------------------------------------
Register Number – 191805
Date – 04/12/2019
Program no – 51
Write a python program to validate the details provided by a user as part of
registering to a web application.
Write a function validate_name(name) to validate the user name
Name should not be empty, name should not exceed 15 characters
Name should contain only alphabets
All the functions should return true if the corresponding value is valid.
Otherwise, it should return false.
Write a function validate_all(name,phone_no,email_id) which should invoke
appropriate functions to validate the arguments passed to it and display
appropriate message. Refer the comments provided in the code.
---------------------------------------------------------------------------------------------------------------'''
def validate_name(name):
if name == "":
return False
if len(name) > 15:
return False
for ch in name:
if not ch.isalpha():
return False
return True
def validate_phone_no(phno):
phone_len = 0
num_list = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
for ch in phno:
unique_count = 0
for i in phno:
if i == ch:
unique_count = unique_count + 1
if unique_count == 10:
return False
phone_len = phone_len + 1
if ch not in num_list:
return False
if phone_len >= 11 or phone_len <= 9:
return False
return True
def validate_email_id(email_id):
at_count = 0
com_count = 0
email_len = len(email_id)
last_com = '.com'
domain_list = ['yahoo', 'gmail', 'hotmail']
for i in range(0, email_len - 3):
if last_com == email_id[i:i+4]:
com_count = com_count + 1
for i in range(0, len(email_id)):
if email_id[i] == '@':
at_flag = i
at_count = at_count + 1
if email_id[i] == '.':
dot_flag = i
if at_count >= 2 or com_count >= 2:
return False
if email_id[at_flag + 1:dot_flag] not in domain_list:
return False
return True
Invalid email id
def purchases(self):
self.bill_amount = self.bill_amount - (self.bill_amount * 0.05)
self.pays_bill(self.bill_amount)
def main():
cust1 = Customer(35000, 'Sana')
cust1.purchases()
main()
OUTPUT:
def get_vehicle_id(self):
return self.vehicle_id
def get_vehicle_type(self):
return self.vehicle_type
def get_vehicle_cost(self):
return self.vehicle_cost
def calculate_premium(self):
if self.vehicle_type == "Two Wheeler":
self.premium_amount = self.vehicle_cost * 0.02
else:
self.premium_amount = self.vehicle_cost * 0.06
def get_premium_amount(self):
return self.premium_amount
def display_vehicle_details(self):
print("Vehicle ID : ", self.get_vehicle_id())
print("Vehicle Type : ", self.get_vehicle_type())
print("Vehicle Cost : ", self.get_vehicle_cost())
print("Vehicle Premium Amount : ", self.get_premium_amount())
def main():
veh_obj = Vehicle()
v_type = ["Two Wheeler", "Four Wheeler"]
veh_obj.set_vehicle_id(int(input("Enter vehicle id : ")))
veh_type = input("Enter vehicle type : ")
if veh_type not in v_type:
print("Error Invalid vehicle Type!!!")
exit()
else:
veh_obj.set_vehicle_type(veh_type)
veh_obj.set_vehicle_cost(float(input("Enter vehicle Cost : ")))
veh_obj.calculate_premium()
veh_obj.display_vehicle_details()
main()
OUTPUT:
def check_eligibility(self):
if self.__inst_exp > 3:
if self.__inst_avg_feedback >= 4.5:
return True
else:
if self.__inst_avg_feedback >= 4:
return True
return False
def main():
name = input("Enter Instructor Name: ")
feedback = float(input("Enter average feedback: "))
exp = int(input("Enter experience "))
tech_skill = list()
n = int(input("Enter no. technology skills known: "))
print("Enter Skills")
for i in range(0, n):
tech_skill.append(input("Skill Name: "))
inst_obj = Instructor(name, feedback, tech_skill, exp)
tech = input("Enter the course to allocate to him: ")
if inst_obj.allocate_course(tech):
print("The instructor is eligible for the course")
else:
print("The instructor is not eligible for the course")
main()
OUTPUT:
Enter experience 6
Enter Skills
def validate_marks(self):
if self.__marks>= 0 and self.__marks<= 100:
return True
else:
return False
def validate_age(self):
if self.__age> 20:
return True
else:
return False
def check_qualification(self):
if self.validate_age() and self.validate_marks():
if self.__marks>= 65:
return True
return False
else:
return False:
def set_student_id(self):
global student_id_counter
self.__student_id = student_id_counter
student_id_counter = student_id_counter + 1
def get_student_id(self):
return self.__student_id
def set_marks(self, marks):
self.__marks = marks
def get_marks(self):
return self.__marks
def get_age(self):
return self.__age
def main():
s1 = Student()
s1.set_student_id(int(input(“Enter Student ID)))
print(s1.get_student_id())
input_age=int(input("enter age"))
s1.set_age(input_age)
print(s1.get_age())
input_marks =int(input("enter marks"))
s1.set_marks(input_marks)
print(s1.get_marks())
s1.check_qualification()
print(s1.check_qualification())
main()
OUTPUT:
Problem Statement:
Complete the CallDetail class with necessary attributes
Complete the logic inside the parse_customer() method of the Util Class. This method
should accept a list of string of the call details and convert it into a list of CallDetail
object and assign this list as a value to the attribute of the Util class.
---------------------------------------------------------------------------------------------------------------'''
class CallDetail:
def __init__(self, phoneno, called_no, duration, call_type):
self.__phoneno = phoneno
self.__called_no = called_no
self.__duration = duration
self.__call_type = call_type
def display_user(self):
print(self.__phoneno, "\t", self.__called_no, "\t", self.__duration, "\t", self.__call_type)
class Util:
def __init__(self):
self.list_of_call_objects = None
return self.list_of_call_objects
call = '9876543210,9876501234,20,STD'
call2 = '9988776655,9844332211,04,Local'
def validate_flower(self):
if self.__flower_name in flowers:
return True
else:
return False
def check_level(self):
if self.validate_flower():
flower_level = levels[flowers.index(self.__flower_name)]
if self.__stock_available<flower_level:
return True
return False
def get_flower_name(self):
return self.__flower_name
def get_price_per_kg(self):
return self.__price_per_kg
def get_stock_available(self):
return self.__stock_available
main()
OUTPUT:
enter the flower name: Orchid
enter the price: 100
enter the available stock: 20
True
---------------------------------------------------------------------------------------------------------------'''
class Bill:
def __init__(self, bill_id, patient_name):
self.__bill_id = bill_id
self.__patient_name = patient_name
self.__bill_amount = None
def get_bill_id(self):
return self.__bill_id
def get_patient_name(self):
return self.__patient_name
def get_bill_amount(self):
return self.__bill_amount
def main():
bill = Bill(123,"Karen")
consultation_fee = 100
quantity_list = [4,2,1]
price_list = [200,400,600]
bill.calculate_bill_amount(consultation_fee, quantity_list, price_list)
a = bill.get_bill_id()
b = bill.get_patient_name()
print("Patient Id =" ,a)
print("Patient Name =", b)
c = bill.get_bill_amount()
print("Patient Total Bill Amount =", c)
main()
OUTPUT:
Patient Id = 123
Patient Name = Karen
Patient Total Bill Amount = 2300
'''--------------------------------------------------------------------------------------------------------------
Register Number – 191805
Date – 04/12/2019
Program no – 59
Write a python program to find out if a given classroom is present in the left wing of a
university building. Implement the class, Classroom given below.
---------------------------------------------------------------------------------------------------------------'''
class Classroom:
classroom_list = None
@staticmethod
def search_classroom(class_room):
for room in Classroom.classroom_list:
print(class_room)
if class_room.lower() == room.lower():
return "The given class room is in left wing of the university building"
return -1
def main():
class_room = input("Enter the class room number:")
Classroom.classroom_list = ["BCA","BSc","BCom"]
class_found = Classroom.search_classroom(class_room)
if(class_found == -1):
print("The given class room is not in left wing of the university building")
else:
print(class_found)
main()
OUTPUT:
Enter the class room number:BSc
BSc
The given class room is not in left wing of the university building
'''--------------------------------------------------------------------------------------------------------------
Register Number – 191805
Date – 04/12/2019
Program no – 60
Write a Python program to implement the class chosen with its attributes and methods.
Represent few parrots, display their names, color and unique number.
---------------------------------------------------------------------------------------------------------------'''
class Parrot:
__counter = 201
def get_name(self):
return self.__name
def get_color(self):
return self.__color
def get_unique_number(self):
return self.__unique_number
def main():
main()
OUTPUT:
Enter the number of Parrots:2
Enter Parrot name:raju
Enter the parrot color:green
Parrot Details
Name of parrot= raju
Color of parrot= green
Unique Number of this parrot is = 202
Enter Parrot name:alien
Enter the parrot color:red
Parrot Details
Name of parrot= alien
Color of parrot= red
Unique Number of this parrot is = 203
'''--------------------------------------------------------------------------------------------------------------
Register Number – 191805
Date – 04/12/2019
Program no – 61
Freight Pvt. Ltd, a cargo company, forwards cargos/freights between its customers.30 min
Freight charges are applied based on weight and distance of the shipment.
Write a python program to implement the class diagram given below.
---------------------------------------------------------------------------------------------------------------'''
class Freight:
counter = 132
self.__recipient_customer = recipient_customer
self.__from_customer = from_customer
self.__weight = weight
self.__distance = distance
self.__freight_charge = None
self.__freight_id = None
def validate_weight(self):
if self.__weight % 5 == 0:
return True
else:
return False
def validate_distance(self):
if 500 <= self.__distance <= 5000:
return True
else:
return False
def forward_cargo(self):
Freight.counter += 2
self.__freight_id = Freight.counter
self.__freight_charge = (150 * self.__weight) + (60 * self.__distance)
def get_recipient_customer(self):
return self.__recipient_customer
def get_from_customer(self):
return self.__from_customer
def get_weight(self):
return self.__weight
def get_distance(self):
return self.__distance
def get_freight_charge(self):
return self.__freight_charge
def get_freight_id(self):
return self.__freight_id
class Customer:
def __init__(self, customer_id, customer_name, address):
self.__customer_id = customer_id
self.__customer_name = customer_name
self.__address = address
def validate_customer_id(self):
def get_customer_name(self):
return self.__customer_name
def get_address(self):
return self.__address
def main():
c = Customer(500000,"Suraj","Kerla")
if(c.validate_customer_id()):
print("Customer ID",c.get_customer_id())
print("Customer Name",c.get_customer_name())
print("Customer Address",c.get_address())
f = Freight("Kim",c.get_customer_name(),100,10000)
if (f.validate_weight()):
print("There is no problem for",f.get_weight(),"kg weight")
if (f.validate_distance()):
print("This distance is valid for shippment")
f.forward_cargo()
print("Freight ID ",f.get_freight_id())
print("Goods Sending Customer ", f.get_from_customer())
print("Goods Receiving Customer ",f.get_recipient_customer())
print("Weight of the good ",f.get_weight())
print("Distance ", f.get_distance())
print("Charge for Freight ",f.get_freight_charge())
main()
OUTPUT:
There is no problem for 100 kg weight
Freight ID 134
Goods Sending Customer Suraj
Goods Receiving Customer Kim
Weight of the good 100
Distance 10000
Charge for Freight 615000
'''--------------------------------------------------------------------------------------------------------------
Register Number – 191805
Date – 04/12/2019
Program no – 62
def get_customer_name(self):
return self.__customer_name
def get_payment_status(self):
return self.__payment_status
def pays_bill(self):
self.__payment_status = "Paid"
class Bill:
counter = 1000
def __init__(self):
self.__bill_id = None
self.__bill_amount = None
def get_bill_id(self):
return self.__bill_id
def get_bill_amount(self):
return self.__bill_amount
self.__bill_amount = 0
self.__bill_id = 'B' + str(Bill.counter)
tmp_dict = item_quantity
a = {}
class Item:
def __init__(self, item_id, description, price_per_quantity):
self.__item_id = item_id
self.__description = description
self.__price_per_quantity = price_per_quantity
def get_item_id(self):
return self.__item_id
def get_description(self):
return self.__description
def get_price_per_quantity(self):
return self.__price_per_quantity
def main():
i = [one,two]
b1 = Bill()
b1.generate_bill_amount(dictnry, i)
print("Details")
print("Customer Name",customer.get_customer_name())
print("Item ID ",one.get_item_id())
print("Item Description ",one.get_description())
print("Item Price Per Quantity ",one.get_price_per_quantity())
print("Item ID ", two.get_item_id())
print("Item Description ", two.get_description())
print("Item Price Per Quantity ", two.get_price_per_quantity())
print("Bill Id ",b1.get_bill_id())
print("Bill amount ",b1.get_bill_amount())
print("Information about payment ",customer.pays_bill())
main()
OUTPUT:
Details
Customer Name Karen
Item ID item1
Item Description Pen
Item Price Per Quantity 200
Item ID item2
Item Description Pencil
Item Price Per Quantity 120
Bill Id B1001
Bill amount 760
Information about payment Paid
'''--------------------------------------------------------------------------------------------------------------
Register Number – 191805
Date – 04/12/2019
Program no – 63
Write a Python program to generate tickets for online bus booking, based on the class
diagram given below.
---------------------------------------------------------------------------------------------------------------'''
class Ticket:
counter = 0
def validate_source_destination(self):
dest = ['goa', 'thane', 'delhi', 'kerla']
if self.__source.lower() == 'mangalore' and self.__destination.lower() in dest:
return True
return False
def generate_ticket(self):
Ticket.counter += 1
if self.validate_source_destination():
if Ticket.counter < 10:
self.__ticket_id = self.__source[0] + self.__destination[0] + '0' + str(Ticket.counter)
else:
self.__ticket_id = self.__source[0] + self.__destination[0] + str(Ticket.counter)
def get_ticket_id(self):
return self.__ticket_id
def get_passenger_name(self):
return self.__passenger_name
def get_source(self):
return self.__source
def get_destination(self):
return self.__destination
def main():
tkt = Ticket("Rajat","Mangalore","Goa")
if tkt.validate_source_destination():
print("Source and destination selected is valid")
tkt.generate_ticket()
print("Ticket ID ",tkt.get_ticket_id())
print("Passenger Name ",tkt.get_passenger_name())
print("Source",tkt.get_source())
print("Destination",tkt.get_destination())
main()
OUTPUT:
Source and destination selected is valid
Ticket ID MK01
Source Mangalore
Destination Goa
'''--------------------------------------------------------------------------------------------------------------
Register Number – 191805
Date – 04/12/2019
Program no – 64
"Infinity" IT solution wants to automate their recruitment process. They have decided to
accept 5 applications for each of the three job bands ("A", "B" and "C") in the company.
Write a Python program to implement the class diagram given below.
---------------------------------------------------------------------------------------------------------------'''
class Applicant:
__application_dict = {'A': 0, 'B': 0, 'C': 0}
__applicant_id_count = 1000
def generate_applicant_id(self):
Applicant.__applicant_id_count += 1
self.__applicant_id = Applicant.__applicant_id_count
@staticmethod
def get_application_dict():
return Applicant.__application_dict
def get_applicant_id(self):
return self.__applicant_id
def get_applicant_name(self):
return self.__applicant_name
def get_job_band(self):
return self.__job_band
def main():
n = int(input("Enter no. of applicants: "))
for i in range(0, n):
print("Applicant ", i + 1)
applicant_obj = Applicant(input("Enter Applicant Name : "))
if applicant_obj.apply_for_job(input("Enter Job Band(A/B/C) : ")) == -1:
print("Cant Apply for the band")
else:
print("Applicant ID : ", applicant_obj.get_applicant_id())
print("Name : ", applicant_obj.get_applicant_name())
print("Applied Job Band : ", applicant_obj.get_job_band())
main()
OUTPUT:
Care hospital management wants to calculate the charge of lab tests done by its patients.Write
a python program to implement the class diagram given below
---------------------------------------------------------------------------------------------------------------'''
class Patient:
def __init__(self, patient_id, patient_name, list_of_lab_test_ids):
self.__patient_id = patient_id
self.__patient_name = patient_name
self.__list_of_lab_test_ids = list_of_lab_test_ids
self.__lab_test_charge = None
def get_patient_id(self):
return self.__patient_id
def get_patient_name(self):
return self.__patient_name
def get_list_of_lab_test_ids(self):
return self.__list_of_lab_test_ids
def get_lab_test_charge(self):
return self.__lab_test_charge
def calculate_lab_test_charge(self):
self.__lab_test_charge = 0
for test in self.__list_of_lab_test_ids: # looping for no. of tests
price = LabTestRepository.get_test_charge(test) # assigning cost as Price
if price == -1: # if get_test_charge in LabTestRepositry is invalid then price is 0
price = 0
self.__lab_test_charge += price
class LabTestRepository:
__list_of_hospital_lab_test_ids = ["I111", "I112", "I113", "I114"]
__list_of_lab_test_charge = [123, 1000, 799, 8000.50]
@staticmethod
def get_test_charge(lab_test_id):
if lab_test_id not in LabTestRepository.__list_of_hospital_lab_test_ids:
return -1
else:
index = LabTestRepository.__list_of_hospital_lab_test_ids.index(lab_test_id)
return LabTestRepository.__list_of_lab_test_charge[index]
pass
# Remove pass and write the logic here.
"FairyLand Multiplex" wants to automate ticket booking and seat allocation process.
Write a python program to implement the class diagram given below.
---------------------------------------------------------------------------------------------------------------'''
class Multiplex:
__list_movie_name = ["movie1", "movie2"]
__list_total_tickets = [90, 80]
__list_last_seat_number = ["M-10", None]
__list_ticket_price = [120, 100]
def __init__(self):
self.__seat_numbers = None
self.__total_price = None
'''Write the logic to book the given number of tickets for the specified movie.'''
if movie_index == 0:
if Multiplex.__list_last_seat_number[0] is None:
lst_tkt = 0
else:
lst_tkt = int(Multiplex.__list_last_seat_number[0].split('-')[-1])
prefix = "M1"
else:
if Multiplex.__list_last_seat_number[1] is None:
lst_tkt = 0
else:
lst_tkt = int(Multiplex.__list_last_seat_number[1].split('-')[-1])
prefix = "M2"
return tkt_list
def get_total_price(self):
return self.__total_price
def get_seat_numbers(self):
return self.__seat_numbers
booking1 = Multiplex()
status = booking1.book_ticket("movie1", 5)
if (status == 0):
print("invalid movie name")
elif (status == -1):
print("Tickets not available for movie-1")
else:
print("Booking successful")
print("Seat Numbers :", booking1.get_seat_numbers())
print("Total amount to be paid:", booking1.get_total_price())
print("-----------------------------------------------------------------------------")
booking2 = Multiplex()
status = booking2.book_ticket("movie2", 1)
if (status == 0):
print("invalid movie name")
elif (status == -1):
print("Tickets not available for movie-2")
else:
print("Booking successful")
print("Seat Numbers :", booking2.get_seat_numbers())
print("Total amount to be paid:", booking2.get_total_price())
OUTPUT:
Booking successful
Seat Numbers : ['M1-11', 'M1-12', 'M1-13', 'M1-14', 'M1-15']
Total amount to be paid: 600
-----------------------------------------------------------------------------
Booking successful
Seat Numbers : ['M2-1']
Total amount to be paid: 100