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.












Source Code:-
'''
Created on 19-Aug-2019
@author: Anonymous
'''
#PF-Assgn-43
def find_factors(num):
#Accepts a number and returns the list of all the factors of a given number
factors = []
for i in range(1,(num+1)):
if(num%i==0):
factors.append(i)
return factors
def find_smallest_number(num):
i=int(1)
while(True):
x=find_factors(i)
if(len(x)==num):
print(x)
break
else:
i=i+int(1)
return x[-1]
#start writing your code here
num=16
print("The number of divisors :",num)
result=find_smallest_number(num)
print("The smallest number having",num," divisors:",result)

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 For example, g(10)=f(10)+f(11)+f(12)+f(13)+f(14)+f(15)+f(16)+f(17)+f(18)=5 + 11 + 3 + 13 + 7 + 5 + 2 + 17 + 3 =66

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

For example,
g(10)=f(10)+f(11)+f(12)+f(13)+f(14)+f(15)+f(16)+f(17)+f(18) 
        =5 + 11 + 3 + 13 + 7 + 5 + 2 + 17 + 3 
        =66 
 Source Code:-
'''
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
For example,
g(10)=f(10)+f(11)+f(12)+f(13)+f(14)+f(15)+f(16)+f(17)+f(18)
=5 + 11 + 3 + 13 + 7 + 5 + 2 + 17 + 3
=66
'''
#PF-Assgn-42
def find_factors(num):
#Accepts a number and returns the list of all the factors of a given number
factors = []
for i in range(2,(num+1)):
if(num%i==0):
factors.append(i)
return factors
def is_prime(num, i):
#Accepts the number num and num/2 --> i and returns True if the number is prime ,else returns False
if(i==1):
return True
elif(num%i==0):
return False;
else:
return(is_prime(num,i-1))
def find_largest_prime_factor(list_of_factors):
large=[]
for i in list_of_factors:
if is_prime(i,i//2)==True:
large.append(i)
return max(large)
#Accepts the list of factors and returns the largest prime factor
def find_f(num):
#Accepts the number and returns the largest prime factor of the number
f=find_factors(num)
l=find_largest_prime_factor(f)
return l
def find_g(num):
#Accepts the number and returns the sum of the largest prime factors of the 9 consecutive numbers starting from the given number
sum=0
consicutive=[i for i in range(num,num+9)]
for i in consicutive:
largest_prime_factor=find_f(i)
sum=sum+largest_prime_factor
return sum
#Note: Invoke function(s) from other function(s), wherever applicable.
print(find_g(10))

A 10-substring of a number is a substring of its digits that sum up to 10. For example, the 10-substrings of the number 3523014 are: 3523014, 3523014, 3523014, 3523014

A 10-substring of a number is a substring of its digits that sum up to 10.

For example, the 10-substrings of the number 3523014 are:
3523014, 3523014, 3523014, 3523014

Write a python function, find_ten_substring(num_str) which accepts a string and returns the list of 10-substrings of that string.

Handle the possible errors in the code written inside the function.

#PF-Assgn-41
def find_ten_substring(num_str):
m=[]
l=[]
for i in range(0,len(num_str)):
for j in range(i,len(num_str)):
m.append(num_str[i:j+1])
for k in set(m):
s=0
for b in range(0,len(k)):
s=s+int(k[b])
if(s==10 and b+1==len(k)):
l.append(k)
return l
#Remove pass and write your logic here
num_str="2825302"
print("The number is:",num_str)
result_list=find_ten_substring(num_str)
print(result_list)

Write a recursive function, is_palindrome() to find out whether a string is a palindrome or not. The function should return true, if it is a palindrome. Else it should return false.

Source Code:-

#PF-Assgn-40
def is_palindrome(word):
word=word.lower()
if(len(word)==1):
return True
elif(len(word)==2):
if(word[0]==word[1]):
return True
else:
return False
elif(len(word)>2 and word[0]==word[-1]):
word=word[1:-1]
result=is_palindrome(word)
if(result):
return True
else:
return False
else:
return False
#Remove pass and write your logic here
#Provide different values for word and test your program
result=is_palindrome("mm")
if(result):
print("The given word is a Palindrome")
else:
print("The given word is not a Palindrome")
view raw #PF-Assgn-40.py hosted with ❤ by GitHub

Represent a small bilingual (English-Swedish) glossary given below as a Python dictionary

{"merry":"god", "christmas":"jul", "and":"och", "happy":"gott", "new":"nytt", "year":"ar"} 

and use it to translate your Christmas wishes from English into Swedish.

That is, write a python function translate() that accepts the bilingual dictionary and a list of English words (your Christmas wish) and returns a list of equivalent Swedish words. 


#PF-Exer-23
def translate(bilingual_dict,english_words_list):
#Write your logic here
swedish_words_list=[]
for i in english_words_list:
for key in bilingual_dict:
if(key==i):
swedish_words_list.append(bilingual_dict[key])
return swedish_words_list
bilingual_dict= {"merry":"god", "christmas":"jul", "and":"och", "happy":"gott", "new":"nytt", "year":"ar"}
english_words_list=["merry","christmas"]
print("The bilingual dict is:",bilingual_dict)
print("The english words are:",english_words_list)
swedish_words_list=translate(bilingual_dict, english_words_list)
print("The equivalent swedish words are:",swedish_words_list)
view raw #PF-Exer-23.py hosted with ❤ by GitHub

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.










Solution:-

https://gist.github.com/newsundram2018/56b3df5125e68b31654c71dd9cc59290

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.

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.


#PF-Assgn-20
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 function, find_correct() which accepts a dictionary and returns a list as per the rules mentioned below. The input dictionary will contain correct spelling of a word as key and the spelling provided by a contestant as the value.

Write a python function,  find_correct()  which accepts a dictionary and returns a list as per the rules mentioned below. The input diction...