InfyTQ Python Assignment-2
1. (Day2-Assignment:19 Level 2)FoodCorner home delivers vegetarian
and non-vegetarian combos to its customer based on order.
A vegetarian combo costs Rs.120 per plate and a non-vegetarian combo
costs Rs.150 per plate. Their non-veg combo is really famous that they
get more orders for their non-vegetarian combo than the vegetarian
combo.
Apart from the cost per plate of food, customers are also charged for
home delivery based on the distance in kms from the restaurant to the
delivery point. The delivery charges are as mentioned below:
Distance in kms Delivery charge in Rs per km
For first 3kms 0
For next 3kms 3
For the remaining 6
Given the type of food, quantity (no. of plates) and the distance in kms
from the restaurant to the delivery point, write a python program to
calculate the final bill amount to be paid by a customer.
The below information must be used to check the validity of the data
provided by the customer:
Type of food must be ‘V’ for vegetarian and ‘N’ for non-vegetarian.
Distance in kms must be greater than 0.
Quantity ordered should be minimum 1.
If any of the input is invalid, the bill amount should be considered as -1.
2. (Day3-Assignment:26 Level 2)Write a python program to solve a
classic ancient Chinese puzzle.
We count 35 heads and 94 legs among the chickens and rabbits in a
farm. How many rabbits and how many chickens do we have?
Sample Input Expected Output
heads-150 legs-400 100 50
heads-3 legs-11 No solution
heads-3 legs-12 03
heads-5 legs-10 50
3. (Day3-Exercise-22 Collaborative Exercise Level 2)Write a python
program to generate the ticket numbers for specified number of
passengers traveling in a flight as per the details mentioned below:
The ticket number should be generated as airline:src:dest:number
where
1. Consider AI as the value for airline
2. src and dest should be the first three characters of the source and
destination cities.
3. number should be auto-generated starting from 101
The program should return the list of ticket numbers of last five
passengers.
Note: If passenger count is less than 5, return the list of all generated
ticket numbers.
Sample Input Expected Output
airline = AI
source = Bangalore
destination = London
no_of_passengers = 10 ['AI:Ban:Lon:106', 'AI:Ban:Lon:107',
'AI:Ban:Lon:108', 'AI:Ban:Lon:109',
'AI:Ban:Lon:110']
airline = BA
source = Australia
destination = France
no_of_passengers = 2 ['BA:Aus:Fra:101', 'BA:Aus:Fra:102']
4. (Assignment-32)Care hospital wants to know the medical speciality visited by
the maximum number of patients. Assume that the patient id of the patient along
with the medical speciality visited by the patient is stored in a list. The details of
the medical specialities are stored in a dictionary as follows:
{
"P":"Pediatrics",
"O":"Orthopedics",
"E":"ENT
}
Write a function to find the medical speciality visited by the maximum number of
patients and return the name of the speciality.
Also write the pytest test cases to test the program.
Note:
Assume that there is always only one medical speciality which is visited by
maximum number of patients.
Perform case sensitive string comparison wherever necessary.
Sample Input Expected Output
[101,P,102,O,302,P,305,P] Pediatrics
[101,O,102,O,302,P,305,E,401,O,656,O] Orthopedics
[101,O,102,E,302,P,305,P,401,E,656,O,987,E] ENT
5. (Assignment-30) Given a string containing uppercase characters (A-Z), compress
the string using Run Length encoding. Repetition of character has to be replaced
by storing the length of that run.
Write a python function which performs the run length encoding for a given
String and returns the run length encoded String.
Provide different String values and test your program.
Sample Input Expected Output
AAAABBBBCCCCCCCC 4A4B8C
AABCCA 2A1B2C1A