ezoic

Wednesday, July 27, 2016

How to pratically learn python from zero: chapter three loops

In programming, loops is used to complete a round of calculations etc.  through a list etc. Ppl use the framework/form to complete a sequence of  calculations etc. through a list etc.

You can loop through a list, a tuple, a sequence, a set etc.

Python has two types of loops, 1. While 2. For

Python does not have do until loop.

Here are the examples for 1.While and 2.For:


Python's while loop does not include 'do' statement:

count=0 
while (count<9):
    count=count+1    print count





For loop example:
a={1,2,3,4}
for i in range(len(list(a))):
    a=list(a)
    print a[i]
 
set does not support indexing, so convert the set to list.

b=[1,2,3,4]
for i in range(len(b)):
    print b[i]

d=(1,2,3,4)

for i in range(len(d)):
    print d[i]
 
We can loop through a dictionary:
 
kk={'a':1,'b':3,'r':8}

for key in kk.keys():
    print key, kk[key]
 
results:
a 1
b 3
r 8
 



And there are three control statements for Python loop: break, continue, pass

Break means the loop stops at where the condition meets:

count=0
while (count<9):
  count=count+1
  if count>5:
        break
  else:
     print count

output

1
2
3
4
5



Pass means we skip the step where the condition meets, it is a little bit similar to break.
 
count=0
 
while (count<9):
    count=count+1
    if count==5:
       pass
    else:
        print count
 
output
1
2
3
4
6
7
8
 

 

Continue returns the control to the beginning of the while loop.. The continue statement rejects all the remaining statements in the current iteration of the loop and moves the control back to the top of the loop.

count=0
while (count<9):
   count=count+1
   if count>5:
       continue
   print count

output
1
2
3
4
5




Wednesday, July 13, 2016

How to pratically learn python from zero: chapter two basics

First, to learn some basic concepts etc, you need a good tutorial, like below:

http://www.tutorialspoint.com/python/


Like many programming language, python uses some computer command to let computer finish some work for ppl. The work can be some computing work, can be software development.

To finish the work, one needs to learn how Python denote numbers, strings, vectors etc. Or in other words what kind of data structures python has.

Python use variable to denote different types of data.

It has several data types:

1. Number

counter=5

Assign 5 to counter. After that, once we refer ti counter, we mean a variable with value 5. 


2.String

string1="Alice"

Put the letters, numbers etc in a single or double quote, and assign to a variable. This variable will have a value in the quote.

Python's single quote, double quote and triple quotes have some different usages.

Here is an article talking about the three quotes:

http://faculty.tarleton.edu/agapie/documents/cs102_intro/lab01_gettingstarted_python2.pdf


3.List

List is like a vector in Python. It put a list of data into a "[]".

The elements in a list can be anything, numbers, strings etc.

list1=[1,2,3,'ak','oop',99]

We can add, remove elements from list. And we can iterate on a list.

add element:

cc="aa"
list1.append(cc)

remove element:

list1.remove('ak')



4.Tuple

Tuple is something included in a "()". And once we create a tuple. We can not alter it like list.

tuple1=(1,2,"wi")


5.Dictionary (hash table in Python)

Dictionary is quoted in "{}". It is some pairs of keys and values. And the keys are unique in a dictionary. I.e. the dictionary's keys can not have duplicates. Otherwise, you will have some error. And each key can have anything as the value, including the list etc.


Dict={"Name":"Alice", "Age": 7, "Height": "6"}

And we can refer to the values of the keys in a dictionary like this:

print Dict['Name']

And the values in a dictionary can be changed.



And you can set up a dictionary by  starting from a empty dictionary.

dic2={}

dic2["game name"]="football"
dic2["number of ppl"]=22
...

And then you can set up a dictionary from an empty dictionary.




Dictionary is a very powerful data type.  It is very useful. And if you analyze some messy data, you will use it a lot maybe.

There is another data type in python. It is called set. It is a list of elements. And the elements are all unique. So we can use set to calculate/get the unique elements in a list.




Operators in Python"

One also needs to know how python do the calculations, +,-,*,/. And it has a modular arithmetic "%".  The modular arithmetic may be different for positive and negative numbers.

The results of the dividing will be determined by the signs of both numbers. If the signs of the both numbers are same, then the results will be positive, otherwise it will be negative.

The results of the modular arithmetic will be determined by the signs of second numbers. If the sign of the second numbers is positive , then the result will be positive, otherwise it will be negative.

And python also has the operator like power. "**".



There are some other operators in Python too. Like the comparison operator, bitwise operators etc.

looking for a man

 I am a mid aged woman.  I was born in 1980. I do not have any kid. no complicated  dating before . I am looking for a man here for marriage...