3

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 :)

2 Answers 2

12

You want random.choice

random.choice(['+', '-'])

Or more concisely:

random.choice('+-')
Sign up to request clarification or add additional context in comments.

Comments

-2

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

1 Comment

Add Import statements to your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.