Python 2.7.7 |Anaconda 2.0.1 (x86_64)| (default, Jun 2 2014, 12:48:16)

Type "copyright", "credits" or "license" for more information.


IPython 2.1.0 -- An enhanced Interactive Python.

Anaconda is brought to you by Continuum Analytics.

Please check out: http://continuum.io/thanks and https://binstar.org

? -> Introduction and overview of IPython's features.

%quickref -> Quick reference.

help -> Python's own help system.

object? -> Details about 'object', use 'object??' for extra details.

%guiref -> A brief reference about the graphical user interface.


In [1]: range(10)

Out[1]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]


In [2]: xrange(10)

Out[2]: xrange(10)


In [3]: for i in range(5):

   ...: print i

   ...:

0

1

2

3

4


In [4]: for i in xrange(5):

   ...: print i

   ...:

0

1

2

3

4


In [5]: range(5)

Out[5]: [0, 1, 2, 3, 4]


In [6]: for i in xrange(5):

   ...: print i

   ...:

0

1

2

3

4


In [7]: runfile('/Users/progprim/Desktop/fifoqueue_outline.py', wdir='/Users/progprim/Desktop')


In [8]: q

Out[8]: []


In [9]: show()


In [10]: add('Hawke')


In [11]: q

Out[11]: ['Hawke']


In [12]: runfile('/Users/progprim/Desktop/fifoqueue_outline.py', wdir='/Users/progprim/Desktop')


In [13]: length()

Out[13]: 0


In [14]: runfile('/Users/progprim/Desktop/fifoqueue_outline.py', wdir='/Users/progprim/Desktop')


In [15]: add('Hawke')


In [16]: show()

['Hawke']


In [17]: add('Hawke', 'Fangohr')

Traceback (most recent call last):


File "<ipython-input-17-e835eceaa892>", line 1, in <module>

add('Hawke', 'Fangohr')


TypeError: add() takes exactly 1 argument (2 given)



In [18]: add('Fangohr')


In [19]: show()

['Hawke', 'Fangohr']


In [20]: length()

Out[20]: 2


In [21]: help(q)

Help on list object:


class list(object)

| list() -> new empty list

| list(iterable) -> new list initialized from iterable's items

|

| Methods defined here:

|

| __add__(...)

| x.__add__(y) <==> x+y

|

| __contains__(...)

| x.__contains__(y) <==> y in x

|

| __delitem__(...)

| x.__delitem__(y) <==> del x[y]

|

| __delslice__(...)

| x.__delslice__(i, j) <==> del x[i:j]

|

| Use of negative indices is not supported.

|

| __eq__(...)

| x.__eq__(y) <==> x==y

|

| __ge__(...)

| x.__ge__(y) <==> x>=y

|

| __getattribute__(...)

| x.__getattribute__('name') <==> x.name

|

| __getitem__(...)

| x.__getitem__(y) <==> x[y]

|

| __getslice__(...)

| x.__getslice__(i, j) <==> x[i:j]

|

| Use of negative indices is not supported.

|

| __gt__(...)

| x.__gt__(y) <==> x>y

|

| __iadd__(...)

| x.__iadd__(y) <==> x+=y

|

| __imul__(...)

| x.__imul__(y) <==> x*=y

|

| __init__(...)

| x.__init__(...) initializes x; see help(type(x)) for signature

|

| __iter__(...)

| x.__iter__() <==> iter(x)

|

| __le__(...)

| x.__le__(y) <==> x<=y

|

| __len__(...)

| x.__len__() <==> len(x)

|

| __lt__(...)

| x.__lt__(y) <==> x<y

|

| __mul__(...)

| x.__mul__(n) <==> x*n

|

| __ne__(...)

| x.__ne__(y) <==> x!=y

|

| __repr__(...)

| x.__repr__() <==> repr(x)

|

| __reversed__(...)

| L.__reversed__() -- return a reverse iterator over the list

|

| __rmul__(...)

| x.__rmul__(n) <==> n*x

|

| __setitem__(...)

| x.__setitem__(i, y) <==> x[i]=y

|

| __setslice__(...)

| x.__setslice__(i, j, y) <==> x[i:j]=y

|

| Use of negative indices is not supported.

|

| __sizeof__(...)

| L.__sizeof__() -- size of L in memory, in bytes

|

| append(...)

| L.append(object) -- append object to end

|

| count(...)

| L.count(value) -> integer -- return number of occurrences of value

|

| extend(...)

| L.extend(iterable) -- extend list by appending elements from the iterable

|

| index(...)

| L.index(value, [start, [stop]]) -> integer -- return first index of value.

| Raises ValueError if the value is not present.

|

| insert(...)

| L.insert(index, object) -- insert object before index

|

| pop(...)

| L.pop([index]) -> item -- remove and return item at index (default last).

| Raises IndexError if list is empty or index is out of range.

|

| remove(...)

| L.remove(value) -- remove first occurrence of value.

| Raises ValueError if the value is not present.

|

| reverse(...)

| L.reverse() -- reverse *IN PLACE*

|

| sort(...)

| L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*;

| cmp(x, y) -> -1, 0, 1

|

| ----------------------------------------------------------------------

| Data and other attributes defined here:

|

| __hash__ = None

|

| __new__ = <built-in method __new__ of type object>

| T.__new__(S, ...) -> a new object with type S, a subtype of T



In [22]: q

Out[22]: ['Hawke', 'Fangohr']


In [23]: q.pop(0)

Out[23]: 'Hawke'


In [24]: q

Out[24]: ['Fangohr']


In [25]: runfile('/Users/progprim/Desktop/fifoqueue_outline.py', wdir='/Users/progprim/Desktop')


In [26]: add('Hawke')


In [27]: add('Fangohr')


In [28]: show()

['Hawke', 'Fangohr']


In [29]: q

Out[29]: ['Hawke', 'Fangohr']


In [30]: next()

Out[30]: 'Hawke'


In [31]: show()

['Fangohr']


In [32]: next()

Out[32]: 'Fangohr'


In [33]: runfile('/Users/progprim/Desktop/eps.py', wdir='/Users/progprim/Desktop')

1.0

0.5

0.25

0.125

0.0625

0.03125

0.015625

0.0078125

0.00390625

0.001953125

0.0009765625

0.00048828125

0.000244140625

0.0001220703125

6.103515625e-05

3.0517578125e-05

1.52587890625e-05

7.62939453125e-06

3.81469726562e-06

1.90734863281e-06

9.53674316406e-07

4.76837158203e-07

2.38418579102e-07

1.19209289551e-07

5.96046447754e-08

2.98023223877e-08

1.49011611938e-08

7.45058059692e-09

3.72529029846e-09

1.86264514923e-09

9.31322574615e-10

4.65661287308e-10

2.32830643654e-10

1.16415321827e-10

5.82076609135e-11

2.91038304567e-11

1.45519152284e-11

7.27595761418e-12

3.63797880709e-12

1.81898940355e-12

9.09494701773e-13

4.54747350886e-13

2.27373675443e-13

1.13686837722e-13

5.68434188608e-14

2.84217094304e-14

1.42108547152e-14

7.1054273576e-15

3.5527136788e-15

1.7763568394e-15

8.881784197e-16

4.4408920985e-16

2.22044604925e-16

final eps = 1.11022302463e-16


In [34]: eps + 1

Out[34]: 1.0


In [35]: eps

Out[35]: 1.1102230246251565e-16


In [36]: 2*eps + 1

Out[36]: 1.0000000000000002


In [37]: runfile('/Users/progprim/Desktop/eps.py', wdir='/Users/progprim/Desktop')

final eps = 0.0


In [38]: runfile('/Users/progprim/Desktop/eps.py', wdir='/Users/progprim/Desktop')

final eps = 4.94065645841e-324


In [39]: a = [0, 2, 4, 6]


In [40]: b = a


In [41]: b

Out[41]: [0, 2, 4, 6]


In [42]: b[0] = 10


In [43]: b

Out[43]: [10, 2, 4, 6]


In [44]: a

Out[44]: [10, 2, 4, 6]


In [45]: bcopy = a[:]


In [46]: id?

Type: builtin_function_or_method

String form: <built-in function id>

Namespace: Python builtin

Docstring:

id(object) -> integer


Return the identity of an object. This is guaranteed to be unique among

simultaneously existing objects. (Hint: it's the object's memory address.)


In [47]: id(a)

Out[47]: 4508265936


In [48]: id(b)

Out[48]: 4508265936


In [49]: id(a) == id(b)

Out[49]: True


In [50]: a is b

Out[50]: True


In [51]: id(bcopy)

Out[51]: 4508412384


In [52]: a is bcopy

Out[52]: False


In [53]: bcopy

Out[53]: [10, 2, 4, 6]


In [54]: a

Out[54]: [10, 2, 4, 6]


In [55]: a == bcopy

Out[55]: True


In [56]: line = "bread 1 1.39"


In [57]: line.split()

Out[57]: ['bread', '1', '1.39']


In [58]: bits = line.split()


In [59]: bits

Out[59]: ['bread', '1', '1.39']


In [60]: type(bits[1])

Out[60]: str


In [61]: bits[1] * bits[2]

Traceback (most recent call last):


File "<ipython-input-61-bf2280cc59f1>", line 1, in <module>

bits[1] * bits[2]


TypeError: can't multiply sequence by non-int of type 'str'



In [62]: bits

Out[62]: ['bread', '1', '1.39']


In [63]: int(bits[1])

Out[63]: 1


In [64]: float(bits[2])

Out[64]: 1.39


In [65]: runfile('/Users/progprim/Desktop/shopping_cost.py', wdir='/Users/progprim/Desktop')


In [66]: line = "12 2 3 4 5 -3"


In [67]: line.split()

Out[67]: ['12', '2', '3', '4', '5', '-3']


In [68]: bits = line.split()


In [69]: runfile('/Users/progprim/Desktop/session4.py', wdir='/Users/progprim/Desktop')


In [70]: compute_sum_of_numbers_in_each_line_for_the_given_file('data.txt')

380

50

17


In [71]: