Python Random Module

Опубликовано: 02 Октябрь 2024
на канале: Parag Dhawan
150
6

Random Module
Goal: Learn python by Implementation.
Objective :
- To understand
0:40 1. Random Function
1:28 2. Randint Function
2:30 3. Randrange Function
6:13 4. Sample Function
7:35 5.Choice Function
8:20 6. Shuffle Function
9:35 7. Seed Function

code:-
import random

Random Function

random.random?

print (random.random())

Randint Function

random.randint?

print(random.randint(5,10))

Randrange Function

toss = random.randrange(2)
print(toss)

if toss == 0:
print ("heads")
else:
print ("tails")


print (random.randrange(1,7,2))

print ("you rolled a die with a score : " + str(random.randrange(1,7)))

Sample Function

random.sample?

sample = random.sample(range(100),5)
print (sample)

Choice Function

random.choice?

Pets= ["cat","dog", "fish"]
print(random.choice(Pets))

Shuffle Function

random.shuffle?

cards = ["Jack","King","queen","Ace"]
a= random.shuffle(cards)
print(cards)
print(a)

Seed Function

for i in range(10):
print(random.randrange(1, 7), end=' ')


random.seed(45)
for i in range(10):
print(random.randrange(1, 7), end=' ')


============================================================================= Link for Tutorial Series

Jupyter Notebook Tutorial Series:-
   • How To Open Jupyter Notebook in Windows  

Python Tutorial Series:-
   • Introduction to Python | Python Appli...  

Python Assignments and Objective Questions:-
   • Objective Questions Python - 1  

Tech. Videos By Parag Dhawan    • Template Matching Using OpenCV (Pytho...  
============================================================================= Feel free to connect and ask your queries:-

Linkedin:-   / parag-dhawan  
Youtube:-    / paragdhawan  
Facebook Page:- http://fb.me/dhawanparag
Instagram: -   / paragdhawan  
Twitter:-   / dhawan_parag  
GitHub:- https://github.com/paragdhawan/
Facebook Profile:- https://www.facebook.com/profile.php?...

============================================================================= Show your support by Subscribing to the channel:-
https://www.youtube.com/c/ParagDhawan... ============================================================================= Link of Next video:-    • Python Math Module  
=============================================================================
#ParagDhawan
#PythonCrashCourse
#Python
#PythonTutorialForBeginners
#PythonForDataScience
#PythonProgramming
#PythonProgrammingLanguage
#PythonTutorial
#PythonCode
#Python3

=============================================================================
Note: Watch the video at a speed of 1.5