Monday, 19 October 2020

How to make a Dice Rolling Simulator using Python ? [ Source code included ]

 Snake and Ladder is a very popular game. We all are familiar with the dice that we use in this game. Here I am explaining a simple program that simulates the dice. I will be using random() function in python to implement this feature. 


 

The random module has so many functionalities and features. Here we will be using the random integer generation feature of the random module.

First lets get the simple program ready. 

import random
dice_value = random.randint(1,6)
print(dice_value)

The random.randint() function is the core logic in this function. The arguments 1 and 6 are the lower and upper limits of the random integer values. The function will return values between both these numbers including these numbers. 

Now let us try to give some more look and feel to the program. I have added some more lines of code to improve usability. This will give a visual effect also.



If you want a more advanced dice simulator, let us modify the program further to with a Graphical User Interface. We will use TKinter package in python to implement this simple user interface.

Sunday, 11 October 2020

How to calculate the area of a triangle using a python program ?

 Calculating the area of a triangle is a very fundamental problem statement. Here I am explaining the calculation of the area of a triangle using Heron's Formula.

What is Heron's Formula ?

This is a formula which has been in use from the past 2000 year. We can easily calculate the area of a triangle if we know the measurement of all the three sides of a triangle.


 As shows in the picture above, if we know all the sides of the triangle a, b and c. We will be able to apply Heron's formula.

Area = (s(s-a) * (s-b) * (s-c)) ^ 0.5

where s = (a+b+c) / 2

We will use the above formula in a python program and make a utility to calculate the area in a programmatic way. 

The sample python program to calculate the area of triangle in given below

How to check the memory utilization of cluster nodes in a Kubernetes Cluster ?

 The memory and CPU utilization of a Kubernetes cluster can be checked by using the following command. kubectl top nodes The above command...