Friday, March 27, 2020

poisson probability mass function in datascience using python

from scipy.stats import poisson
import matplotlib.pyplot as plt
import numpy as np

mu =500
x=np.arange(400,600,0.5)
plt.plot(x,poisson.pmf(x,mu))

output:

threading example in python

from threading import *
import time
e=Event()
def consumer():
    print("consumer thread is waiting for updation")

    e.wait()
    print("consumer got notification and consuming items")

def producer():
    time.sleep(5)
    print("producer thread is producing items")
    print("producer thread giving notification by setting  event")
    e.set()
   
t1=Thread(target=producer)
t2=Thread(target=consumer)
t1.start()
t2.start()

output:
consumer thread is waiting for updation
producer thread is producing items
producer thread giving notification by setting  event
consumer got notification and consuming items

number guess game using python

'''
 You decide you want to play a game where you are hiding
 a number from someone.  Store this number in a variable
 called 'answer'.  Another user provides a number called
 'guess'.  By comparing guess to answer, you inform the user
 if their guess is too high or too low.

 Fill in the conditionals below to inform the user about how
 their guess compares to the answer.
'''
answer = int(input("enter a number as ans"))#provide answer
guess =int(input("enter a number as guess")) #provide guess

if answer > guess :
    #provide conditional
    result = "Oops!  Your guess was too low."
elif answer < guess : #provide conditional
    result = "Oops!  Your guess was too high."
elif answer == guess : #provide conditional
    result = "Nice!  Your guess matched the answer!"

print(result)

output:
enter a number as ans56

enter a number as guess47
Oops!  Your guess was too low.

if elif else in python

"""

Points Prize
1 - 50 wooden rabbit
51 - 150 no prize
151 - 180 wafer-thin mint
181 - 200 penguin
"""

num=int(input("enter a number"))
if num > 1 and num <=50 :
    print("Congratulations! You won a wooden rabbit!")
elif num > 50 and num <=150:
    print("Oh dear, no prize this time.")
elif num > 150 and num <=180:
    print("Congratulations! You won a wafer-thin mint!")
elif num > 180 and num <=200:
    print("Congratulations! You won a penguin")
else :
     print("Oh dear, no prize this time.")

output:
enter a number173
Congratulations! You won a wafer-thin mint!

dictionary in python


elements = {'hydrogen': {'number': 1, 'weight': 1.00794, 'symbol': 'H'},
            'helium': {'number': 2, 'weight': 4.002602, 'symbol': 'He'}}

print(elements)
print("\n hydrogen:",elements['hydrogen'])
print("\n hydrogen_no:",elements['hydrogen']['number'])
print("\n hydrogen_weight:",elements['hydrogen']['weight'])
print("\n hydrogen_symbols:",elements['hydrogen']['symbol'])

print("\n helium:",elements['helium'])

output:
{'hydrogen': {'number': 1, 'weight': 1.00794, 'symbol': 'H'}, 'helium': {'number': 2, 'weight': 4.002602, 'symbol': 'He'}}

 hydrogen: {'number': 1, 'weight': 1.00794, 'symbol': 'H'}

 hydrogen_no: 1

 hydrogen_weight: 1.00794

 hydrogen_symbols: H

 helium: {'number': 2, 'weight': 4.002602, 'symbol': 'He'}


example 2:
cast = {
           "Jerry Seinfeld": "Jerry Seinfeld",
           "Julia Louis-Dreyfus": "Elaine Benes",
           "Jason Alexander": "George Costanza",
           "Michael Richards": "Cosmo Kramer"
       }
for key in cast:
    print(key)

output:
Jerry Seinfeld
Julia Louis-Dreyfus
Jason Alexander
Michael Richards

Bio nomial probability in datascience using python

from scipy.stats import binom
import matplotlib.pyplot as plt
import numpy as np

n,p=10,0.5

x=np.arange(0,10,0.001)
plt.plot(x,binom.pmf(x,n,p))

output:



exponential pdf/ power Law in datascience using python

from scipy.stats import expon
import matplotlib.pyplot as plt
import numpy as np

x=np.arange(0,10,0.001)
plt.plot(x,expon.pdf(x))

output:

python class topic video