PythonPlacement Classroomnotes 21/Mar/2022

Write a Program in Python for the following scenario

  • Problem 1: We have 4 digit numbers on number plates, i want the sum in following way
4299 => 4+2+9+9 => 24 => 2+4 => 6
0414 => 9
  • Donot use lists, str to represent a number.
def sum(registration_number):
    """
    This method is used to return the sum of registration numbers
    """
    total = 0
    while registration_number > 0:
        total = total + registration_number%10
        registration_number = registration_number//10
    if total <= 9:
        return total
    else:
        return sum(total)

  • When we want to solve problems using programming languages, we need to think in terms of

    • datatype
    • operators
    • sequence of steps
      • conditional statements
      • looping constructors
  • Problem 2: write a function in python which will calculate the EMI based on principal and interest rate Refer Here

def calculate_monthly_installment(
    principal, 
    rate_of_intrest, 
    duration, 
    processing_fee_percent=0):
    """
    This method should calculate monthly installment

    params:
      prinicpal: Amount of the product purchased
      rate_of_intrest: rate of interest
      duration: duration in months
      processing_fee_percent: processing fee percent default is zero

    Returns:
       monthly installment
    """
    pass

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner