Resources
Answers
Examples
Sign in
Get Started
What do you want to save?
Add Code snippet
New code examples
Python
2022-01-24 01:46:28
create a typo with python
import string import random new_phrase = [] words = phrase.split(' ') for word in words: outcome = random.random() if outcome <= p: ix = random.choice(range(len(word))) new_word = ''.join([word[w] if w != ix else random.choice(...
Add solution
Python
2022-01-23 00:01:27
python random choice from list
import random #1.A single element random.choice(list) #2.Multiple elements with replacement random.choices(list, k = 4) #3.Multiple elements without replacement random.sample(list, 4)
Add solution
Python
2021-11-21 08:11:16
random letter generator python
import random import string random.choice(string.ascii_letters)
Add solution
Python
2021-11-20 10:32:13
numpy random choice
fruits = ['apple', 'banana', 'orange', 'grape'] subset_size = int(0.7 * len(fruits)) np.random.choice(fruits, subset_size, replace=False) # array(['grape', 'banana'], dtype='<U6')
Add solution
Java
2021-11-20 07:02:37
java random number generator in range
int rand = ThreadLocalRandom.current().nextInt(x,y);
Add solution
Python
2021-11-20 01:35:14
animal quiz game in python
animal_list = ['Fish' , 'Tarantula' , 'Snake' , 'an Octopus'] animal=random.choice(animal_list) print("Choice an animal:Fish,Tarantula,Snake and Octopus") if
Add solution
Python
2021-11-17 22:11:21
how to call a random function in python
import random print(random.randint(3, 7)) #Prints a random number between 3 and 7 array = [cars, bananas, jet] print(random.choice(array)) #Prints one of the values in the array at random
Add solution
Python
2021-11-17 06:40:13
sample 1 item from array python
import random cakes = ['lemon', 'strawberry', 'chocolate'] random.choice(cakes) # prints 1 randomly selected item from the collection of n items with # the probability of selection as 1/n
Add solution
Python
2021-11-15 03:40:09
python coin flip
# Import the RANDOM library. import random as RANDOM # the 'as RANDOM' part could be optionial, # it's just choosing a name for the import. def flip(): flipped = RANDOM.choice('Heads','Tails') print(f'You flipped {flipped}')
Add solution
Python
2021-11-12 21:08:10
choice random word in python from a text file
import random print(random.choice(open('file.txt').read().split()).strip())
Add solution
‹
1
2
3
4
5
6
7
8
›
Best helpers
daily
weekly
monthly
for 3 months
Ranking is empty
This website uses cookies to make IQCode work for you. By using this site, you agree to our
cookie policy
Welcome Back!
Sign up to unlock all of IQCode features:
Test your skills and track progress
Engage in comprehensive interactive courses
Commit to daily skill-enhancing challenges
Solve practical, real-world issues
Share your insights and learnings
Sign in
E-mail
Password
Recover lost password
Log in
Or log in with
Not registered?
Sign up takes less than a minute
Create a Free Account
Sign up to unlock all of IQCode features:
Test your skills and track progress
Engage in comprehensive interactive courses
Commit to daily skill-enhancing challenges
Solve practical, real-world issues
Share your insights and learnings
Sign up
Email
Password
Sign up for free
Or sign up with
By signing up, you agree to the
Terms and Conditions
and
Privacy Policy
. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.