def printing(self):
     """
     Description:
     taking input from the user no of times to flip the coin
     Parameters:
     :the input in integer format
     :The initial position is zero for both"""
     print("Enter no of time to flip coin :")
     n = int(input())
     head=0
     tail=0
     if n!=0:
         for i in range(0, n):
             #Taking random number for each time of the loop running.
             x = random.random()
             #If random number is less than 0.5 it counted as Tails else false.
             if x<0.5:
                 head=head+1
             else:
                 tail=tail+1
         #Finding the percentage of heads and tails.
         headPercentage = head*100/n
         tailPercentage = tail*100/n
         logger.info(headPercentage)
         logger.info(tailPercentage)
         print("Head Percentage = ", headPercentage, "%")
         print("Tail Percentage = ", tailPercentage, "%")
     else:
         #You give input in null value its shows no result.
         print("You have entered 0 Value, it is not possible")
Example #2
0
 def Factors(self):
     """
     Description:
     Here we are defining the functions as factor
     Parameters:
     :the input as integer format"""
     print("Enter Number : ")
     n = int(input())
     print("Prime factors for", n, "is")
     #Printing the factors of a given number until it is divided by 2.
     while n % 2 == 0:
             logger.info("2")
             n = n / 2
     #If the given number is not even then this loop will print the remaining factors.
     for i in range(3, int(math.sqrt(n)+1)):
         while n % i == 0:
             logger.info(i);
             n = n / i
         i+=2
     #If the remaining factor is greater than 2 it will be printing
     if n > 2:
         logger.info(n)
     else:
         print()
Example #3
0
try:
    class Factors:
        def Factors(self):
            """
            Description:
            Here we are defining the functions as factor
            Parameters:
            :the input as integer format"""
            print("Enter Number : ")
            n = int(input())
            print("Prime factors for", n, "is")
            #Printing the factors of a given number until it is divided by 2.
            while n % 2 == 0:
                    logger.info("2")
                    n = n / 2
            #If the given number is not even then this loop will print the remaining factors.
            for i in range(3, int(math.sqrt(n)+1)):
                while n % i == 0:
                    logger.info(i);
                    n = n / i
                i+=2
            #If the remaining factor is greater than 2 it will be printing
            if n > 2:
                logger.info(n)
            else:
                print()
    nums = Factors()
    nums.Factors()
except Exception as e:
    logger.info(e)
"""
@date = '20/04/2021'
@modified_date = '21/04/2021'
@author = 'vishnu'
@Title = 'Power of 2 '
"""
import math
import logging
from Basiclogger import logger
logger.setLevel(logging.INFO)
"""
Description:
:we are define function as power
Parameters:
:in that function we are assign the input like integer format."""
try:

    N = int(input('enter number from 1 to 31: '))
    if N > 31 and N >= 0:
        print('please enter number from 1 to 31')
    else:
        for i in range(N):
            result = pow(2, i)
            logger.info(result)
except Exception as e:
    logger.info(e)
@author = 'vishnu'
@Title = 'Leap Year'
"""
import logging

from Basiclogger import logger

try:
    year = int(input('Enter year: '))
    logger.setLevel(logging.INFO)
    """
    Description:
    :we are defining the leap year
    Parameters:
    :We give input in integer format."""
    if year < 999:
        #The input is grater than 999(year is grater than 4 digit).
        logger.info('invalid year, please enter 4 digit year value')
    else:
        if year % 4 == 0 and year % 100 != 0:
            logger.info("is a Leap Year")
            logger.info(year)
        elif year % 100 == 0:
            logger.info(year, "is not a Leap Year")
        elif year % 400 == 0:
            logger.info(year, "is a Leap Year")
        else:
            logger.info("is not a Leap Year")
            logger.info(year)
except Exception as e:
    logger.info(e)
Example #6
0
"""
@date = '20/04/2021'
@modified_date = '21/04/2021'
@author = 'vishnu'
@Title = 'Harmonic Number '
"""
import logging

from Basiclogger import logger

logger.setLevel(logging.INFO)
try:
    n = int(input('Enter the value of N:'))
    """
    Description:
    :The input format is in integer
    Parameters:
    :integer value is must be greaterthan zero."""
    if n <= 0:
        logger.info('Please enter value greater then 0')
    else:
        Result = 0
        for i in range(1, n + 1):
            #The Range between 1 to n+1
            # Every time of the loop taking the sum of the next harmonic number
            H = 1 / i
            Result += H
            print(n, "th Value", 1 / i)
            logger.info(Result)
except Exception as e:
    logger.info(e)
Example #7
0
"""
@date = '20/04/2021'
@modified_date = '21/04/2021'
@author = 'vishnu'
@Title = 'User Input and Replace String Template “Hello <<UserName>>, How are you?”'
"""
import logging

from Basiclogger import logger

logger.setLevel(logging.INFO)
try:
    """
    Description:
    :we are replace the string Template "Hello <<UserName>>, How are you?"
    parameters:
    :in we are assign input String format"""

    String = "Hello <<UserName>>, How are you?"
    """we pass the input as String format"""
    name = str(input("Enter your name: "))
    if len(name) < 3:
        logger.info('min name length is 3 characters')
    else:
        string = String.replace("<<UserName>>", name)
        logger.info(string)
except Exception as e:
    logger.info(e)