What is the meaning of Data Structure?
Data Structure is the building that save and manipulate the data of your program in it in memory, in your real life imagine you save your things in a box :) or in your office temporarily to use it later,here's the same a box in memory (Structure) to hold your data temporarily to make you able to use and manipulate it as you want
Data Structure = Place in memory to hold your data in organized way
So , Data Structure can contain a collection of data elements like (numbers , characters ,or even another data structures)
The most basic data structure in python is the sequence , each element of a sequence is assigned a number (its position , or index)
the first index is zero the second is one and so on
Python Data Structure:
1. List
2.Tuple
3.Dictionaries
4.Sets
Simple script to convert binary to decimal in python
Here is a simple code to convert binary numbers to decimal ,I do not handle if the user enter a letter or decimal numbers ,it is just simple to do the purpose
sum=0 counter=0 l=[] userInput=input("Enter binary number : ") userInput[::-1] for i in userInput: sum=sum+(int(i)*pow(2,counter)) counter=counter+1 print(sum)
How to easily install django on windows (simple way)
About four or five monthes ago I was a completely beginner in django ,I know python seince a year ago but I wanted to work with web development ,so I started to read about web development in python and the frameworks working with web ,I read about django and how it was a great framework to make a web app in it , I tried to install it in my computer (windows) and it did not work , but I did not give up :) I tried again and again I read here and there about a simple way , in a lot of sites they advice to install a lot of libraries to get the django worked but all of what I need is just to see it worked ,I do not want to make a great app :) am just a beginner , also in django official site although they write a lot of ways to install django but I feel conflict when I read then ,later I followed one way of them :)
well,I am a talkative I know :) let's get into the point
Firstly ,I have downloaded django using git , go to git official site and download it , then start it and write the following command to download django:
git clone git://github.com/django/django.git django-trunk
or
wait untill it finish
it will create two folders one named django and the other named django-trunk
copy them to c:\\
drive as I install widows files and programs there
you just downloaded django but you did not install it till now ,lets install it
open command shell ( run ) and then go to django folder through command shell
and write >>setup.py install
Let's make sure it was installed correctly
start python IDLE and write >>import django
wait untill it finish
it will create two folders one named django and the other named django-trunk
copy them to c:\\
drive as I install widows files and programs there
you just downloaded django but you did not install it till now ,lets install it
open command shell ( run ) and then go to django folder through command shell
and write >>setup.py install
start python IDLE and write >>import django
Best free python IDE
As a brginner you search on free IDEs to help you accomplish your tasks,here I recommend free IDEs for you and fell free to enrich my knowlage If you know best
1.pyscripter : free open scource IDE , with a lot of feartures
Error types in python:Syntax error , Logical error , Exception error
As we know that there are a lot of error types that might happen during the programming process,one kind of it is called a Syntax Error which occured when you violate the rules of writing the code or in another mean as it's name reffere when there is an error in the syntax of the language , this error in fact is easy to detected by the compiler ,the compiler will show you what is the error and also the number of line the error in.
Example:writing incorrect function name,does not importing a module ,usually in languages like java and c++ it is occured because of forgoting the semicolon ( ; )
another type of errors is called Logical Error this error usually occur but you do not feel about it ,the program will run without any problem but the problem is with the meaning of the program it self you may want your code to add two numbers and write it ' -' in your formula
sum=number1 - number2 ,here there is no violation of the syntax of the language ,every thing is Allright but the code does not do its job.
The third type of errors is called Runtime Error and as it;s name reffere it is occured at the run time of the code .
Let's take an example :
Let's take an example :
Factorial using recursion in python
Simple function to calculate factorial of number using recursion in python
def factorial(n):
fact=1
if n==0:
return 1
elif n==1:
return 1
else:
fact=factorial(n-1)*n
return fact
Calculate factorial of a number in python
This is a simple function to calculate the factorial of any number in python
def factorial(n): if n==1: return 1 elif n==0: return 1 else: fact=1 for i in range(2,n+1): fact=fact*i return fact
code that write astrick * pyramids in python
*
**
***
****
*****
******
*******
********
*********
**********
**
***
****
*****
******
*******
********
*********
**********
s="*" i=0 while i<10: print(s) s=s+'*' i=i+1
Calculate area of circle in python3
Here in this code I imported math module to use PI constant ,created new function named circleArea that take one parameter that is the radius to process on it and return area
becuase of input function take string so we need to cast the string to int using int() function
import math def circleArea(r): area=(r*r)*(math.pi) return area r=input("Enter Radius : ") print("Area of Circle is:{0}".format(circleArea(int(r))))
Subscribe to:
Posts
(
Atom
)
No comments :
Post a Comment