I want to have Python print "Yes" 70% of the time, and "No" 30% of the time. How should I go about doing so?
Asked
Active
Viewed 495 times
-8
-
2How would you do it manually, e.g. with a pencil and paper? – ChrisGPT was on strike Dec 31 '20 at 16:28
-
1https://docs.python.org/3/library/random.html – Jared Smith Dec 31 '20 at 16:28
1 Answers
3
You can use the random
module:
from random import random
while True:
prob = random()
if prob >= 0.3:
print("Yes")
else:
print("No")

Jacob
- 225
- 1
- 9