Skip to main content


Showing posts from December, 2018

Learn Python From Basics. Part 1!

This is going to be a long session of python programming. From this session, we are going to learn about basic python syntax and structures and then move on to the advanced topics. I have divided python into eight different topics. In this blog, we will take a look at the first two pieces. I have tried to make this session as simple as possible and as much interactive as I could. So, what are we waiting for? Let's dive in! Feel free to comment on any part you find difficult.
The eight key pieces  to learn at first in Python are: 1. Data Types 2. Object References 3. Collection Data Types 4. Logical Operations 5. Control Flow Statements 6. Arithmetic Operators 7. Input/Output 8. Creating and Calling Functions 1. Data Types:  There are several built-in data types in python. Here we are going to discuss some of them. In python, the integer has no limit. It is only limited by the machine's m…

How to write PROLOG program for half adder?

In this problem, we are going to implement some logic (of course it is all about logic) that will run calculate the half adder sum and carry. We know has two inputs, and it will give sum and carry which looks like this:

X            Y                 Sum                 Carry
0            0                  0                      0
0            1                  1                      0         
1            0                  1                      0
1            1                  0                      1

So, to implement sum we need XOR gate and to implement Carry we need AND gate.

Here is how we do it:



halfadder(X,Y,S,C):-xORGate(X,Y,S), aNDGate(X,Y,C). 

Now, you can run this code by giving the values of X and Y.
like this:
halfadder(1,1,S,C)  and the output will be