Relative Content

Tag Archive for pythonrandom

Randomly choosing two elements in a list [duplicate]

This question already has answers here: How do you pick “x” number of unique numbers from a list in Python? (7 answers) Closed last year. Is there a better way to select two distinct elements from a list? foo = [‘1′,’a’,’3′,’f’,’ed’] elt1 = random.choice(foo) elt2 = random.choice(foo) while elt2 == elt1: elt2 = random.choice(foo) python […]

EOF error in using a sample function of random module

I am creating a simple password generator application using python, since I new about random module so I employed it’s sample() function with a sequence of characters and length. But it is showing me this EOF error as

lil prob with random.randint

import time, random count = (1, 10) while count < 5: random.randint(count) time.sleep(1) else: print(“YEhahhhh”) When I run the code gives me error: Traceback (most recent call last) line 3, in <module> while count < 5: ^^^^^^^^^ TypeError: ‘<‘ not supported between instances of ‘tuple’ and ‘int python random New contributor Armin Codes is a […]

How to I get another number from a random.randint in python?

I am trying to make a random number guesser game, and if the user gets it, I ask them if they want to play again. Problem is, if they say yes, the random number will be the same as it was last time. I am new to python and would really apprectate it if you could help me. Also, if there is anything I can inprove on, please tell me!