Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 12

Q1)

Problem Statement
Write a python program to find and display the product of three positive integer
values based on the rule mentioned below:

It should display the product of the three values except when one of the integer
value is 7.
In that case, 7 should not be included in the product and the values to its left
also should not be included.
If there is only one value to be considered, display that value itself. If no
values can be included in the product, display -1.

Note: Assume that if 7 is one of the positive integer values, then it will occur
only once. Refer the sample I/O given below.

Sample Input

Expected Output

1, 5, 3

15

3, 7, 8

7, 4, 3

12

1, 5, 7

-1

Note: Assignment should be done in Eclipse Plug-in

#lex_auth_012693711503400960120

def find_product(num1,num2,num3):
product=0
#write your logic here
if(num3==7):
product=-1 #Checking is num3 has 7 then we consider -1
elif(num2==7):
product=num3 #Checking id num2 has 7 then we take last number
elif(num1==7):
product=num2*num3 #checking if num1 has 7 then we take product rest num2
and num3
else:
product=num1*num2*num3 #checking if any postion doesn't have 7 then we take
entire product
return product

#Provide different values for num1, num2, num3 and test your program
product=find_product(7,6,2)
print(product)
Q2)
Problem Statement
Write a python function to check whether three given numbers can form the sides of
a triangle.
Hint
: Three numbers can be the sides of a triangle
if none of the numbers are greater than or equal to the sum of the other two
numbers.

#lex_auth_012693802383794176153

#Pyhon Function
def form_triangle(num1,num2,num3):
#Do not change the messages provided below
success="Triangle can be formed"
failure="Triangle can't be formed"

#Write your logic


if(num1+num2 <= num3) or (num1+num3 <= num2) or (num2+num3 <= num1): #3+3 <=5 F
or 3+5 <= 3 F or 3+5 <=3 T # F or F or T F or T ==> T
return failure
else:
return success

#Use the following messages to return the result wherever necessary


return success
return failure

#Provide different values for the variables, num1, num2, num3 and test your program
num1=3
num2=3
num3=5
form_triangle(num1, num2, num3) # function call

Q3)Problem Statement
You have x no. of 5 rupee coins and y no. of 1 rupee coins.
You want to purchase an item for amount z.
The shopkeeper wants you to provide exact change.
You want to pay using minimum number of coins.
How many 5 rupee coins and 1 rupee coins will you use? If exact change is not
possible then display -1.

Sample Input

Expected Output

Available Rs. 1 coins

Available Rs. 5 notes

Amount to be made

Rs. 1 coins needed

Rs. 5 notes needed


2

21

11

11

19

-1

#lex_auth_012693780491968512136
def make_amount(rupees_to_make,no_of_five,no_of_one):
five_needed=0
one_needed=0
#Start writing your code here
#Populate the variables: five_needed and one_needed
five_needed=rupees_to_make//5
if(five_needed>no_of_five):
five_needed=no_of_five # Segregated number five rupees coin possibility

one_needed=(rupees_to_make-five_needed*5)

if(one_needed>no_of_one):
one_needed=no_of_one # segregate number of one rupees coin possibility

# Use the below given print statements to display the output


# Also, do not modify them for verification to work
if((five_needed*5+one_needed)==rupees_to_make):
print("No. of Five needed :", five_needed)
print("No. of One needed :", one_needed)
else:
print(-1)
#Provide different values for rupees_to_make,no_of_five,no_of_one and test your
program
make_amount(28,8,5)

Q4)Problem Statement
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

For next 3kms

For the remaining

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.

#lex_auth_012693782475948032141

def calculate_bill_amount(food_type,quantity_ordered,distance_in_kms):
bill_amount=0
#write your logic here
if(food_type=="N" or food_type=="V") and (quantity_ordered>=1) and
(distance_in_kms>0):
#segreagate for vegiterian
if(food_type=="V"):
if(distance_in_kms<=3):
bill_amount=120*quantity_ordered+0 #distance is 0 kms
elif((distance_in_kms>3) and (distance_in_kms<=6)):
bill_amount=120*quantity_ordered+((distance_in_kms-3)*3) #distance
between 0 to 3kms
else:
bill_amount=120*quantity_ordered+((distance_in_kms-6)*6)+9
#distance between 0 to 3kms
else:
if(distance_in_kms<=3):
bill_amount=150*quantity_ordered+0
elif((distance_in_kms>3) and (distance_in_kms<=6)):
bill_amount=150*quantity_ordered+((distance_in_kms-3)*3) #distance
between 0 to 3kms
else:
bill_amount=150*quantity_ordered+((distance_in_kms-6)*6)+9
#distance between 0 to 3kms
else:
bill_amount=-1
return bill_amount
#Provide different values for food_type,quantity_ordered,distance_in_kms and test
your program
bill_amount=calculate_bill_amount("N",2,7)
print(bill_amount)

Q5)
Problem Statement
The Metro Bank provides various types of loans such as car loans,
business loans and house loans to its account holders.
Write a python program to implement the following requirements:

Initialize the following variables with appropriate input values:account_number,


account_balance, salary, loan_type, loan_amount_expected and customer_emi_expected.

The account number should be of 4 digits and its first digit should be 1.

The customer should have a minimum balance of Rupees 1 Lakh in the account.

If the above rules are valid, determine the eligible loan amount and the
EMI that the bank can provide to its customers based on their salary and the loan
type they expect to avail.

The bank would provide the loan, only if the loan amount and the number of
EMI’s requested by the customer is less than or equal to the loan amount and the
number of EMI’s decided by the bank respectively.

Display appropriate error messages for all invalid data. If all the
business rules are satisfied ,then display account number, eligible and requested
loan amount and EMI’s.
Test your code by providing different values for the input variables.

Salary

Loan type

Eligible loan amount

No. of EMI’s required to repay

> 25000

Car
500000

36

> 50000

House

6000000

60

> 75000

Business

7500000

84

#lex_auth_012693788748742656146

def
calculate_loan(account_number,salary,account_balance,loan_type,loan_amount_expected
,customer_emi_expected):
eligible_loan_amount=0
bank_emi_expected=0
eligible_loan_amount=0
#Start writing your code here
if(account_number>999 and account_number<2000):
if(account_balance>=100000):
#If a person has salary of 250000 then he is eligible for 500000 rs of
loan
if(salary>25000) and (loan_type=="Car"):
eligible_loan_amount=500000 # loan amount
bank_emi_expected=36 # EMI
#IF the person i=has more than 25000 salary the below code is
explaining for the different salaries

if(customer_emi_expected<=bank_emi_expected)and(loan_amount_expected<=eligible_loan
_amount):
print("Account number:", account_number)
print("The customer can avail the amount of Rs.",
eligible_loan_amount)
print("Eligible EMIs :", bank_emi_expected)
print("Requested loan amount:", loan_amount_expected)
print("Requested EMI's:",customer_emi_expected)
else:
print("The customer is not eligible for the loan")

#Person who's salary is >25000 and <50000 is eleibile for car and House
loan
elif(salary>50000 and ((loan_type=="Car") or (loan_type=="House")):
eligible_loan_amount=6000000
bank_emi_expected=60 # EMI
#IF the person i=has more than 25000 salary the below code is
explaining for the different salaries

if(customer_emi_expected<=bank_emi_expected)and(loan_amount_expected<=eligible_loan
_amount):
print("Account number:", account_number)
print("The customer can avail the amount of Rs.",
eligible_loan_amount)
print("Eligible EMIs :", bank_emi_expected)
print("Requested loan amount:", loan_amount_expected)
print("Requested EMI's:",customer_emi_expected)
else:
print("The customer is not eligible for the loan")
#Person who's salary is >25000 and <50000 is eleibile for
car and House loan
elif(salary>75000 and ((loan_type=="Business") or (loan_type=="Car") or
(loan_type=="House")):
eligible_loan_amount=7500000
bank_emi_expected=84 # EMI
#IF the person i=has more than 25000 salary the below code is
explaining for the different salaries

if(customer_emi_expected<=bank_emi_expected)and(loan_amount_expected<=eligible_loan
_amount):
print("Account number:", account_number)
print("The customer can avail the amount of Rs.",
eligible_loan_amount)
print("Eligible EMIs :", bank_emi_expected)
print("Requested loan amount:", loan_amount_expected)
print("Requested EMI's:",customer_emi_expected)
else:
print("The customer is not eligible for the loan")
else:
print("Invalid Loan type or salary")
else:
print("Insufficient account balance")
else:
print("Invalid account number")
#Populate the variables: eligible_loan_amount and bank_emi_expected
#Use the below given print statements to display the output, in case of success
#print("Account number:", account_number)
#print("The customer can avail the amount of Rs.", eligible_loan_amount)
#print("Eligible EMIs :", bank_emi_expected)
#print("Requested loan amount:", loan_amount_expected)
#print("Requested EMI's:",customer_emi_expected)

#Use the below given print statements to display the output, in case of invalid
data.
#print("Insufficient account balance")
#print("The customer is not eligible for the loan")
#print("Invalid account number")
#print("Invalid loan type or salary")
# Also, do not modify the above print statements for verification to work
#Test your code for different values and observe the results
calculate_loan(1001,40000,250000,"Car",300000,30)

Q6)
Problem Statement
Write a python program which finds the maximum number from num1 to num2 (num2
inclusive) based on the following rules.
1. Always num1 should be less than num2

2. Consider each number from num1 to num2 (num2 inclusive).


Populate the number into a list, if the below conditions are satisfied

a. Sum of the digits of the number is a multiple of 3

b. Number has only two digits

c. Number is a multiple of 5

3. Display the maximum element from the list

In case of any invalid data or if the list is empty, display -1.

#lex_auth_012693813706604544157

def find_max(num1, num2):


max_num=-1
# Write your logic here
#inbuilt function range() and the numbers stored into list in sequence +1
list1=list(range(num1,num2+1))
#let's store the numbers into list
list2=[]
#let's check number num1 is less then num2 (Always num1 should be < num2 )
if(num1<num2):
#I will store into temporary value so the can append it to the list
for i in list1:
temp = i # complete range of numbers
temp1 = 0
# swapping the number
while(temp!=0):
temp1=temp1+temp%10
temp=temp//10
#now checking the numbers multiple for 3 and 5 also numbers should be
two digits
if(temp1%3==0 and i%5 ==0 and len (str(i)) == 2):
list2.append(i) # takes exactly one arguments
if(len(list2)!=0):
list2.sort()
max_num=list2[-1]
else:
max_num=-1
return max_num
#Provide different values for num1 and num2 and test your program.
max_num=find_max(10,15)
print(max_num)

Q7)
Write a Python program to generate the next 15 leap years starting from a given
year.
Populate the leap years into a list and display the list.

#lex_auth_012693797166096384149

def find_leap_years(given_year):

# Write your logic here


list_of_leap_years = list()
# we need to find 15 years of leap year from the given year -- 2000 to 2015
while len(list_of_leap_years) < 15:
if(given_year%400==0 or (given_year%4==0 and given_year%100!=0)): # counts
only once ----> in order to continue we need increment
list_of_leap_years.append(given_year)
given_year=given_year+1

return list_of_leap_years

list_of_leap_years=find_leap_years(2000)
print(list_of_leap_years)

Q9)
Problem Statement
ARS Gems Store sells different varieties of gems to its customers.

Write a Python program to calculate the bill amount to be paid by


a customer based on the list of gems and quantity purchased.
Any purchase with a total bill amount above Rs.30000 is entitled for 5% discount.
If any gem required by the customer is not available in the store, then consider
total bill amount to be -1.

Assume that quantity required by the customer for any gem will always be greater
than 0.

Perform case-sensitive comparison wherever applicable.

#lex_auth_012693795044450304151

def calculate_bill_amount(gems_list, price_list, reqd_gems,reqd_quantity):


bill_amount=0
#Write your logic here

# check required gems are not available


for i in reqd_gems:
if i not in gems_list:
bill_amount=-1
return bill_amount
#Generate bill if gems are available
for i in range(len(reqd_gems)):
res=gems_list.index(reqd_gems[i])
bill_amount=bill_amount+price_list[res]*reqd_quantity[i]

#apply 5% discount if purchange is >30000


if(bill_amount>30000):
bill_amount=bill_amount-(5/100)*bill_amount
return bill_amount

#List of gems available in the store


gems_list=["Emerald","Ivory","Jasper","Ruby","Garnet"]

#Price of gems available in the store. gems_list and price_list have one-to-one
correspondence
price_list=[1760,2119,1599,3920,3999]

#List of gems required by the customer


reqd_gems=["Ivory","Emerald","Garnet"]
#Quantity of gems required by the customer. reqd_gems and reqd_quantity have one-
to-one correspondence
reqd_quantity=[3,10,12]

bill_amount=calculate_bill_amount(gems_list, price_list, reqd_gems, reqd_quantity)


print(bill_amount)

Q10)
Problem Statement
Write a python function, create_largest_number(),
which accepts a list of numbers and returns the largest number possible by
concatenating the list of numbers.
Note: Assume that all the numbers are two digit numbers.

Sample Input

Expected Output

23,34,55

553423

#lex_auth_01269441913243238467

def create_largest_number(number_list):
#number_list.sort()
#res=str(number_list[-1])+str(number_list[-2])+str(number_list[-3])
#return int(res)
#remove pass and write your logic here

return int(''.join(sorted(map(str,number_list),reverse=True)))

number_list=[23,45,67]
largest_number=create_largest_number(number_list)
print(largest_number)

Q11)Problem Statement
Write a function, check_palindrome() to check whether the given string is a
palindrome or not.
The function should return true if it is a palindrome else it should return false.

Note: Initialize the string with various values and test your program.
Assume that all the letters in the given string are all of the same case. Example:
MAN, civic, WOW etc.

#lex_auth_012693819159732224162

def check_palindrome(word):
return word[:]==word[::-1]
#Remove pass and write your logic here

status=check_palindrome("Malayalam")
if(status):
print("word is palindrome")
else:
print("word is not palindrome")

Q12) Problem Statement


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

#lex_auth_012693816331657216161

def encode(message):

#Remove pass and write your logic here


if len(message) == 1:
return '1' + message

result = ""
count = 1 # Start counting the first character

for i in range(1, len(message)):


if message[i-1] == message[i]:
count += 1
else:
result += str(count) + message[i-1]
count = 1 # Reset count for the new character

# Add the last set of characters


result += str(count) + message[-1]
return result

#Provide different values for message and test your program


encoded_message=encode("ABBBBCCCCCCCCAB")
print(encoded_message)

Q13)
Assignment on Tuple - Level 2
Problem Statement
A teacher is conducting a camp for a group of five children.
Based on their performance and behavior during the camp, the teacher rewards them
with chocolates.
Write a Python function to

1. Find the total number of chocolates received by all the children put together.
Assume that each child is identified by an id and it is stored in a tuple and
the number of chocolates given to each child is stored in a list.

2. The teacher also rewards a child with few extra chocolates for his/her best
conduct during the camp.

If the number of extra chocolates is less than 1, an error message "Extra


chocolates is less than 1", should be displayed.

If the given child Id is invalid, an error message "Child id is invalid" should be


displayed.
Otherwise, the extra chocolates provided for the child must be added to his/her
existing number
of chocolates and display the list containing the total number of chocolates
received by each child.

#lex_auth_01269442027919769669

#Global variables
child_id=(10,20,30,40,50)
chocolates_received=[12,5,3,4,6]

def calculate_total_chocolates():
return sum(chocolates_received)
#Remove pass and write your logic here to find and return the total number of
chocolates

def reward_child(child_id_rewarded,extra_chocolates):
if(extra_chocolates <1):
print("Extra chocolates is less than 1")
return
if(child_id_rewarded not in child_id):
print("Child id is invalid")
return
chocolates_received[child_id.index(child_id_rewarded)] += extra_chocolates
print(chocolates_received)
#Remove pass and write your logic here
# Use the below given print statements to display the output
# Also, do not modify them for verification to work
#print("Extra chocolates is less than 1")
#print("Child id is invalid")
print(calculate_total_chocolates())
#Test your code by passing different values for child_id_rewarded,extra_chocolates
reward_child(20,2)

You might also like