D Programming – Variables

Hi there, I recently enjoyed learning some programming languages which are new to me. I came across with the D Programming Language. I have already put up an article on the codes on the basic console output in D located here: https://arjunaraneta.wordpress.com/2014/09/27/d-basic-output/

You can think of variables as an address in your memory that contains data that you’ll need and use. The syntax for using variables in python in very straightforward.

Here is a basic example of declaring a variable named x with a value of 10. After declaring and assigning a value, the program will output the value of x.

import std.stdio;

int main(){
int x = 10;
writeln("x = ", x);

  return 0;
}

The output should be:

x = 10

On the next example below, I declared two variables named x and y. I assigned a value for each of the variables. After assigning the values, I created another variable named z assigned the sum of x and y. The program will output the result after the addition.

import std.stdio;

int main(){
	int x = 10, y = 5;
	writeln("x + y = ", x + y);
	
	return 0;
}

The output should be:

x + y = 10

Thank you for your time 🙂
Please leave a comment below.
Be free to ask me questions.

Advertisements

D – Basic Output

In this tutorial, I will be introducing you to a language called D. We will be creating a simple program that outputs “Hello World” on the screen.

First, you should download D here: http://dlang.org/download.html

 

Then, install the software. Installation is very easy because all you need to do is read and follow the directions.

 

After installation, create a new folder in My Documents named tutorials.

While inside the tutorials folder, create a new text document and rename it output.d.

Open the file with your favorite text editor (I love to use Notepad++).

Type the codes same as below:

d1

 

 

Open your command prompt.

Next, change your directory using the cd command.

type dmd then the name of your file

type the name of the exe file that was generated.

our output should be the same as below:

 

d2

 

 

Thank you for reading this post.

Don’t forget to leave a comment.

Python – GUI (Grid Layout)

In this tutorial, I will be demonstrating Graphical User Interface
Programming using Python.

The codes are below:

 

gui2

 

 

Our output should be the same as below:

 

gui1

 

 

Explanation:

 

These lines:

Label(master, text=”Name:”).grid(row=0)
Label(master, text=”Age:”).grid(row=1)

– one way of declaring one or more labels and giving them their position in the grid

While these lines:

E1 = Entry(master)
E2 = Entry(master)

E1.grid(row=0, column=1)
E2.grid(row=1, column=1)

-another way of declaring one or more textboxes then giving their position in separate lines.

 

Thank you for reading this post.

Don’t forget to leave a comment or suggestion. 🙂

Python – GUI (Label and Textbox)

In this tutorial, I will be demonstrating Graphical User Interface
Programming using Python.

The codes are below:

gui1

 

Our output should be the same as below:

gui2

 

 

Explanation:

 

The lines:

top = Tk()

top.mainloop()

– are used to initialize the form

 

The lines:

L1 = Label(top, text=”First Name”)

L1.pack( side = LEFT)

-used to initialize and position the Label to the left with a caption of First Name

 

The lines:

E1 = Entry(top, bd =5)

E1.pack(side = RIGHT)

-used to initialize and position the text box to the right.

 

Thank you very much for reading this post.

Don’t forget to leave a comment or suggestion. 🙂

Python – GUI (Button)

In this tutorial, I will be demonstrating Graphical User Interface
Programming using Python.

The codes are below:

gui1

 

Our output should be the same as below:

gui2

gui3

 

There are several points needed to be explained here.
The import keyword on the first two lines are used to use the libraries native to Python.
Tkinter and tkMessageBox are used for basic GUI Programming.

The lines:

top = Tkinter.Tk()
B.pack()
top.mainloop()

are used to initialize the main form of the program

On this part:

def helloCallBack():
tkMessageBox.showinfo(“Hello Python”, “Hello World”)

  • the def keyword is the same as the function block in other languages
  • the showinfo has two parameters which are:
    “Hello Python” is the used as the title of the Message Box
    “Hello World” is the message inside the Message Box

The line:

B = Tkinter.Button(top, text =”Hello”, command = helloCallBack)

is the initialization of the Button which contains three parameters
top is the position of the button inside the box
text is the String that is used to name the button
command points to function where the button goes when it is clicked

 

Thank you for reading my post.
Don’t forget to leave a comment.

Python – If Statement

Most of the time, every programmer feels the need to compare on or two values of variables in your program. Same as most of the programming languages, Python also has its syntax for the If Statement. In this article, I created a program that uses an if statement after the variables x, and y are declared. I assigned values 10 and 5 to variables x and y respectively.

The program is below:

if1

Your output should be the same as here:

if2

Thank you for reading this post.

Don’t forget to leave a comment.

Python – Loops(While Loop)

This article is a continuation of this last post:
https://arjunaraneta.wordpress.com/2014/08/26/python-loopsfor-loop/

The difference is I used a while in this program. The syntax of the for and while loops and different in terms of the codes used but the concept of a block with a starting value, ending value, and a process of increase and decrease are the same.

 

Here is my code.

loop3

 

Your output should be the same as below:
loop2

 

Thank you for reading this post.