Python - Random Program
Random program:
# comments
from random import random #we are importing random from random module
def flip_coin():
r = random() #assigning the random value to r
if r > 0.5: #if value is greater than 0.5 then
return "Heads"
else:
return "tails"
print(flip_coin()) # print the output . we need to call the function , hence flip_coin() with parenthesis.
output:
Comments
Post a Comment