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


Program

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(salary>25000 and loan_type=="Car"):
                eligible_loan_amount=500000
                bank_emi_expected=36
                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")
            elif(salary>50000 and (loan_type=="Car" or loan_type=="House")):
                eligible_loan_amount=6000000
                bank_emi_expected=60
                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")
            elif(salary>75000 and (loan_type=="Car" or loan_type=="House" or loan_type=="Business")):
                eligible_loan_amount=7500000
                bank_emi_expected=84
                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)
#calculate_loan(loan_amount_expected-7500000,loan_type-Business,account_number-1005,customer_emi_expected-80,account_balance-100000,salary-90000)
calculate_loan(1005,90000,100000,"Business",7500000,80)

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

0 3

heads-5 legs-10

5 0

 

def solve(heads,legs):
error_msg="No solution"
chicken_count=0
rabbit_count=0
if(heads>=legs):
print(error_msg)
elif(legs%2!=0):
print(error_msg)
else:
rabbit_count=(legs-2*heads)/2
chicken_count=heads-rabbit_count
print(int(chicken_count),int(rabbit_count))
#Start writing your code here
#Populate the variables: chicken_count and rabbit_count
# Use the below given print statements to display the output
# Also, do not modify them for verification to work
#print(chicken_count,rabbit_count)
#print(error_msg)
#Provide different values for heads and legs and test your program
solve(38,131)


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.

def find_max(num1, num2):
list2=[]
max_num=-1
list1=list(range(num1,num2+1))
if num1>=num2:
max_num=-1
else:
for i in list1:
temp = i
temp1=0
while temp!=0:
temp1+=temp%10
temp=temp//10
if temp1%3==0 and i%5 ==0 and len(str(i)) == 2:
list2.append(i)
if(len(list2)!=0):
list2.sort()
max_num = list2[-1]
else:
max_num=-1
return max_num
max_num=find_max(24,29)
print((max_num)