Heads or tails in python with Source code

Heads or tails in python with Source code

Introduction

Heads or tails is a simple project predicting whether it is tails or heads. It is like flipping the coin in the air to find heads or tails.

In this tutorial, we will be learning to create heads or tails projects with a few lines of code. We are writing a python code. When you execute the code you will get tails or front heads once randomly. First we must import a random function. The random function is an inbuilt function in python. It is useful in generating a random number between a certain range.

We use if else statement for decision making and printing whether the output is tails or heads. It is a simple beginner project to understand about randomization or random function. And this is how random function works. Random function is the mostly and frequently used function during web and app development. See the code below.


Python code for heads or tails

Import random
Random_side = random.randint(0,1)
if random_side == 1:
    print(“Heads”)
else:
    print(“Tails”)

The output will be generated whether heads, tails randomly.

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Leave a Reply

Your email address will not be published. Required fields are marked *