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

deploying Machine learning Model : pkl, Flask,postman

1)Create model and train          #  importing Librarys         import pandas as pd         import numpy as np         import matplotlib . pyplot as plt         import seaborn as sns         import requests         from pickle import dump , load         # Load Dataset         url = "http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"         names = [ "sepal_length" , "sepal_width" , "petal_length" , "petal_width" , "species" ]         # Loading Dataset         df = pd . read_csv ( url , names = names )         df . tail ( 11 )         df . columns         test = [         { 'sepal_length' : 5.1 , 'sepal_width' : 3.5 , 'peta...

Binomial Distribution

  The binomial distribution formula is:                                                    b(x; n, P) =  n C x  * P x  * (1 – P) n – x Where: b = binomial probability x = total number of “successes” (pass or fail, heads or tails etc.) P = probability of a success on an individual trial n = number of trials Note:  The binomial distribution formula can also be written in a slightly different way, because  n C x  = n! / x!(n – x)! (this binomial distribution formula uses factorials  (What is a factorial? ). “q” in this formula is just the probability of failure (subtract your probability of success from 1). Using the First Binomial Distribution Formula The binomial distribution formula can calculate the probability of success for binomial distributions. Often you’ll be told to “plug in” the numbers to the  formul...

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