Reputation: 41
What is the easiest way to generate a random +
,-
,*
, or /
sign using the import random function while assigning this to a letter.
E.G.
g = answeryougive('+','-')
Thanks in advance :)
Upvotes: 3
Views: 6738
Reputation: 1
Thanks i am doing my GCSE great help
there are several ways to do this but the best is using random.choice for random symbols or random.radiant for numbers Eg.
import random
Num1=random.radiant(1,12) #random number one
Num2=random.radiant(1.12) #random number two
sym=random.choice(['+','/','*'.'-']) #random symbol
Upvotes: -2
Reputation: 97631
You want random.choice
random.choice(['+', '-'])
Or more concisely:
random.choice('+-')
Upvotes: 12