# Category Archive programming

Bydiwas

### Python Program to Find the Gravitational Force Between Two bodies

How to do :

1. Take input of masses of the body of same unit .
2. Take input of distance between two bodies.
3. calculate the gravitational force between them by the expression (f=G*m1*m2/d*d)

source code:

`m1=float(input("Enter the mass of first body: "))m2=float(input("Enter the mass of second body: "))r=float(input("Enter the distance between  of the masses: "))G=6.673e-112f=(Gm1m2)/(r**2)print("Required gravitational force is: ",f,"N")`

output:

Explanation:

1. Program take input of masses and distance between the bodies.
2. Program calculate the gravitational forces between the bodies.
3. Program print the result.

Bydiwas

### Python program to merge two list.

How to start:

1. Take two list from from the user.
2. Then , merge two list and show the result.

Source code:

`a=[]c=[]n1=int(input("Enter number of elements:")) for i in range(1,n1+1):     b=int(input("Enter element:"))     a.append(b)n2=int(input("Enter number of elements:")) for i in range(1,n2+1):     d=int(input("Enter element:"))     c.append(d) n=a+c new.sort()print("Sorted list is:",n)`

Output:

Explanation:

1. User input number of element and element for two list .
2. Program add two list and print result.
Bydiwas

### Python Program to Print Table of a Given Number

How to do?

1. Take input number(to form table) from the user .
2. Process to make formation of table through lopping

Source code:

`n=int(input("Enter the no.to generate mul table:"))for i in range(1,12):     print(n,"x",i,"=",n*i)`

Explanation:

1. program ask user to input number to generate multiplication table.
2. Program starts looping to generate table.

Output:

Bydiwas

### Shorting of elements in c programing using bubble short.

firstly , we need to know about bubble short . what is happening during bubble shorting.

>>> In Bubble short elements of one position is compare to the next position and arrange the elements whatever we want.

Here is the source code example for bubble short.

``````void main()
{
int array[10];
int i, j, num, temp;
printf("Enter number of elements  \n");
scanf("%d", &num);
printf("Enter the elements\n");
for(i = 0; i < num; i++)
{
scanf("%d", &array[i]);
}
for (i = 0; i < num; i++)
{
for (j = 0; j < (num - i - 1); j++)
{
if (array[j] > array[j + 1])
{
temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
}
printf("required shorted array is\n");
for (i = 0; i < num; i++)
{
printf("%d\n", array[i]);
}
}``````

Output:

Explanation:

1.firstly , program ask user to input number of elements and ask for enter elements.

2.After getting the elements program start to compare all the elements inside the for loop.

using: if (array[j] > array[j + 1])
{
temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
} this block.

3.And lastly print the required shorting elements.

Bydiwas

### shorting of elements in c programming

There are many ways to short the given elements in c programming .

let us look different process of shorting of elements in c programming one by one.

1. Bubble short.
2. selection short.
3. merge short.
Bydiwas

### Simple key press event using python

we can create simple key press event using python by
binding the keys of the keyboard by using canvas.bind_all
function .
example: canvas.bind_all(‘<KeyPress-w>’,self.up)

Here is the simple example of key bind function:

`from tkinter import * import time import random win=Tk() win.title("game") canvas=Canvas(win,width=500,height=500) canvas.pack() t=("red","green","blue","grey","pink","black","yellow","orange") class Bind():       def __init__(self,color,size):              self.canvas=canvas              self.shape=canvas.create_oval(10,10,size,size,fill=color)              self.x=random.randint(10,30)             self.y=random.randint(-10,5)             canvas.move(self.shape,250,250)             self.canvas.bind_all('<KeyPress-d>', self.left)             self.canvas.bind_all('<KeyPress-a> ', self.right)             self.canvas.bind_all('<KeyPress-w> ', self.up)             self.canvas.bind_all('<KeyPress-s> ', self.down)       def draw(self):       self.canvas.move(self.shape, self.x, self.y)       po=canvas.coords(self.shape)       if po[0]<=0 or po[2]>=500:             self.x=-self.x       if po[1]<=0 or po[3]>=500:             self.y=-self.y       def  left(self,evt):              self.x=-10       def  right(self,evt):              self.x=10       def up(self,evt):             self.y=-10       def down(self,evt):             self.y=10ball=Bind(random.choice(t),90) while 1:   ball.draw()   win.update()   time.sleep(0.05)`

Bydiwas

### What is Julia Programming language?

Julia is the dyamic programming language is one of the popular language , in case the matter is come about the scientific computing, no other language can beat julia.
Itâ€™s a free and open source programming language which is very much capable of providing high-performance(high speed) comparing to other languages like python,matlab etc. and now a days julia is competing with other programming language.

## history of julia

well, julia was developed in usa at MIT .
The lead developers Alan Edelman, Jeff Bezanson, Stefan Karpinski and Viral Shah  in the year 2012.

## main reason for develope julia.

well, as we all know all programming languages have its own advantages and disadvantages .which is one language can develop fast but its execution is very slow (like python,matlab,r etc) in other hand developement is really slow but its execution is very fast (like c,c++ ).

To solve this problem julia was develop. we have already learn julia is a dynamic language as well as julia combines python’s with c’performance.

That means ,julia is the combination of python and c.we have already discuss about the performance of python and c .These means julia is fast in development as well as in execution. and it easily breaks the barrier between dynamic and static programming language.

Bydiwas

### Python Program to Count the Number of Vowels Present in a String using Sets

To count the number of vowels in a string we need to do following steps.

1. reading the string from the user.
2. create a set of string containing vowels
3. compare the given string to the set of vowels.
4. count the number of vowels if match found.
5. print the result.

For that source code is given below:

`s=input("Enter string:") cnt = 0 vowels="aeiou"for letter in s:     if letter in vowels:         cnt = cnt+1 print("Count of the vowels is:") print(cnt)`

output:

Explanation:

1. user have to input the string.
2. program will compare the given string with (aeiou ) inside for loop.
3. if match found cnt will increment and print the output.

Bydiwas

### Bouncing ball animation in python using tkinter(canvas)

To create a bouncing ball animation .firstly we need to import tkinter and create a canvas .

The source code is given below:

correct the spaces in the program

``````from tkinter import *
import time
import random
win=Tk()
canvas=Canvas(win,width=400,height=500)
canvas.pack()
class Ball():
def __init__(self,color,size):
self.shape=canvas.create_oval(10,10,size,size,fill=color)
self.xspeed=random.randint(1,6)#user can give suitable speed
self.yspeed=random.randint(5,10)#user can give suitable speed
def Move(self):

canvas.move(self.shape,self.xspeed,self.yspeed)
pos=canvas.coords(self.shape)
if pos[3]>=500 or pos[1]<=0:
self.yspeed=-self.yspeed
if pos[2]>=400 or pos[0]<=0:
self.xspeed=-self.xspeed
redball=Ball("red",60)
greenball=Ball("green",100)
orangeball=Ball("orange",60)#here user can create another ball
while True:
redball.Move()
greenball.Move()
orangeball.Move()
#if user create annother ball then user must call the move function inside while loop
win.update()
time.sleep(0.05)``````

Bydiwas

### python program to find largest and smallest number in a list .

To find largest and smallest number in a list using python programming .

firstly, we need to input elements in a list and print the output which one is largest and which one smallest .

The code is given below:

`n=int(input("Enter the number of elements to be in the list:")) b=[] for i in range(0,n):         a=int(input("Enter elements:")     b.append(a)b.shot()print("largest number= ",b[n-1])print("smallest number= ",b[0])                                             `

Explanation:

1)user must input the number of elements and elements

2) Then elements will append(to add elements in a list from left to right) in the list a[] .inside the for loop because to read the element in each time and to append yo the list .

3) Then shorting of list happen.obviously in the list a .the 1st position and last position is the smallest and largest number in list.and lastly print the output .