“py random.smple” Réponses codées

py random.smple

# Python3 program to demonstrate
# the use of sample() function .
  
# import random 
import random
  
  
# Prints list of random items of
# length 3 from the given list.
list1 = [1, 2, 3, 4, 5, 6] 
print("With list:", random.sample(list1, 3))
  
# Prints list of random items of
# length 4 from the given string. 
string = "GeeksforGeeks"
print("With string:", random.sample(string, 4))
  
# Prints list of random items of
# length 4 from the given tuple.
tuple1 = ("ankit", "geeks", "computer", "science",
                   "portal", "scientist", "btech")
print("With tuple:", random.sample(tuple1, 4))
  
  
# Prints list of random items of
# length 3 from the given set.
set1 = {"a", "b", "c", "d", "e"}
print("With set:", random.sample(set1, 3))
Disturbed Deer

py random.smple

# Python3 program to demonstrate
# the use of sample() function .
  
# import random 
import random
  
  
# Prints list of random items of
# length 3 from the given list.
list1 = [1, 2, 3, 4, 5, 6] 
print("With list:", random.sample(list1, 3))
  
# Prints list of random items of
# length 4 from the given string. 
string = "GeeksforGeeks"
print("With string:", random.sample(string, 4))
  
# Prints list of random items of
# length 4 from the given tuple.
tuple1 = ("ankit", "geeks", "computer", "science",
                   "portal", "scientist", "btech")
print("With tuple:", random.sample(tuple1, 4))
  
  
# Prints list of random items of
# length 3 from the given set.
set1 = {"a", "b", "c", "d", "e"}
print("With set:", random.sample(set1, 3))
Disturbed Deer

py random.smple

# Python3 program to demonstrate
# the use of sample() function .
  
# import random 
import random
  
  
# Prints list of random items of
# length 3 from the given list.
list1 = [1, 2, 3, 4, 5, 6] 
print("With list:", random.sample(list1, 3))
#  With list: [3, 1, 2]

# Prints list of random items of
# length 4 from the given string. 
string = "GeeksforGeeks"
print("With string:", random.sample(string, 4))
#  With string: ['e', 'f', 'G', 'G']  
  
# Prints list of random items of
# length 4 from the given tuple.
tuple1 = ("ankit", "geeks", "computer", "science",
                   "portal", "scientist", "btech")
print("With tuple:", random.sample(tuple1, 4))
#  With tuple: ['ankit', 'portal', 'geeks', 'computer']
  
# Prints list of random items of
# length 3 from the given set.
set1 = {"a", "b", "c", "d", "e"}
print("With set:", random.sample(set1, 3))
#  With set: ['b', 'd', 'c']
Disturbed Deer

Réponses similaires à “py random.smple”

Questions similaires à “py random.smple”

Plus de réponses similaires à “py random.smple” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code