Skip to main content

functions

 1. dedine fuction for % marks

    def percent(marks):
        p = ((marks[0+ marks[1+ marks[2]+ marks[3])/400 )*100
        return p

    marks1 = [45788677]
    percentage1 = percent(marks1)

    marks2 = [75988878]
    percentage2 = percent(marks2)
    print(percentage1percentage2)

O/P:

>>  71.5 84.75

2. simple function

    def greet(name):
        print("good day, "+ name)


    def mysum(num1num2):
        return num1 + num2

    greet(avi)
    s= mysum(1213)
    print(s)

O/P:

>>  good day, avi

25

3. default agrument

    def greet(name="strenger"):
        print('Good day, ' + name)

    greet("avi")
    greet()

O/P:

>> Good day, avi

Good day, strenger

4. Recursive method

    factorial by simple method
    n=5
    product= 1
    for i in range(n):
        product= product*(i+1)
    print(product)

    def factorial_iter(n):
        product=1
        for i in range(n):
            product = product* (i+1)
        print(product)

    factorial_iter(5)

    def factorial_recursive(n):
        if n==1 or n==0:
            return 1
        return n * factorial_recursive(n-1)

    print(factorial_recursive(5))

O/P:

>> 120

120

120

5. define function to find max number

    def maximum(num1num2num3):
        if (num1>num2):
            if(num1>num3):
                return num1
            else:
                return num3
        else:
            if(num2>num3):
                return num2
            else:
                return num3

    m = maximum(13552)
    print("The value of the maximum is " + str(m))

O/P:

>>  The value of the maximum is 55

6.  define function for cecius to faherehit

    def farh(cel):
        return (cel *(9/5)) + 32

    c = 0
    f = farh(c)
    print("Fahreheit Temperature is " + str(f))

O/P:

>> Fahreheit Temperature is 32.0

7.  print on single line

print("Hello"end=" ")
print("How"end=" ")
print("are"end=" ")
print("you?"end=" ")

O/P:

>> Hello How are you? 

8. sum with recursive

    def sum(n):
        if n==1:
            return 1
        return (n + sum(n-1))

    s= sum(10)
    print(s)

O/P:

>>  55

9. print star

n = 3
for i in range(n):
    print ("*" * (n-i))

O/P:

>> 

***

**

*

10. define function inch to cm

    def cm(inch):
        return (inch*2.54)

    c= cm(25)
    print(c'cm')

O/P:

>>  63.5 cm

11.  function to Remove specific word from string

    def remov_split(stringword):
        new_str= string.replace(word"")
        return new_str.strip()

    this = "avi is good"
    s = remov_split(this'avi')
    print(s)

O/P:

>>  is good

12.

O/P:

>> 

1.27.

O/P:

>> 

1.

O/P:

>> 

1.O/P:

>> 

1.

O/P:

>> 

1.27.

O/P:

>> 

1.

O/P:

>> 

1.O/P:

>> 

1.

O/P:

>> 

1.27.

O/P:

>> 

1.

O/P:

>> 

1.O/P:

>> 

1.

O/P:

>> 

1.27.

O/P:

>> 

1.

O/P:

>> 

1.O/P:

>> 

1.

O/P:

>> 

1.27.

O/P:

>> 

1.

O/P:

>> 

1.O/P:

>> 

1.

O/P:

>> 

1.27.

O/P:

>> 

1.

O/P:

>> 

1.O/P:

>> 

1.

O/P:

>> 

1.

Popular posts from this blog

cammand for installing library in python

 Command for installing in jupyter notebook:                pip install library_name                ex. pip install nump installing from anaconda prompt:           1. pip install numpy           2.   conda install -c conda-forge matplotlib search for conda command for matplotlib and go to official website. Installing from anaconda navigator easy. Somtime give error then open as administrator

spark-scala-python

 ############sparkcontest######33333 it is used in earlier spark 1.x //scala  import org.apache.spark.SparkConf     import org.apache.spark.SparkContext     val conf = new SparkConf().setAppName("first").setMaster("local[*]")     val sc = new SparkContext(conf) val rdd1 = sc.textFile("C:/workspace/data/txns") # python  from pyspark import SparkContext,SparkConf     conf = SparkConf().setAppName("first").setMaster("local[*])     sc = SparkContext(conf)      ## now days sparksession are used  ########range######### // in Scala val myRange = spark.range(1000).toDF("number") # in Python myRange = spark.range(1000).toDF("number") ###########where########## // in Scala val divisBy2 = myRange.where("number % 2 = 0") # in Python divisBy2 = myRange.where("number % 2 = 0") ###########read csv ########## // in Scala val flightData2015 = spark .read .option("inferSchema", "true") .o...

Bagging and Boosting

  What is an Ensemble Method? The ensemble is a method used in the machine learning algorithm. In this method, multiple models or ‘weak learners’ are trained to rectify the same problem and integrated to gain desired results. Weak models combined rightly give accurate models. Bagging Bagging is an acronym for ‘Bootstrap Aggregation’ and is used to decrease the variance in the prediction model. Bagging is a parallel method that fits different, considered learners independently from each other, making it possible to train them simultaneously. Bagging generates additional data for training from the dataset. This is achieved by random sampling with replacement from the original dataset. Sampling with replacement may repeat some observations in each new training data set. Every element in Bagging is equally probable for appearing in a new dataset.  These multi datasets are used to train multiple models in parallel. The average of all the predictions from different ensemble models i...