In [1]:
print "Hello World"
Hello World
In [1]:
2+2
Out[1]:
4
In [2]:
3-2
Out[2]:
1
In [3]:
2**3
Out[3]:
8
In [4]:
8%5
Out[4]:
3
In [5]:
2.1+2
Out[5]:
4.1
In [6]:
2.5 == 2.5
Out[6]:
True
In [7]:
print 4.1
4.1
In [8]:
5/2
Out[8]:
2
In [9]:
from __future__ import division
5/2
Out[9]:
2.5
In [10]:
9.0/5
Out[10]:
1.8
In [11]:
(1+2j)
Out[11]:
(1+2j)
In [12]:
(1+2j)-(3+4j)
Out[12]:
(-2-2j)
In [13]:
t=1.0, accel = 9.8
  File "<ipython-input-13-97e205ccfbda>", line 1
    t=1.0, accel = 9.8
SyntaxError: can't assign to literal
In [14]:
t, accel = 1.0, 9.8
In [15]:
'0b1110'
Out[15]:
'0b1110'
In [16]:
0b1110
Out[16]:
14
In [17]:
0b1110 << 1
Out[17]:
28
In [18]:
0b1110 & 0b100
Out[18]:
4
In [19]:
0b1110 & 0b1000
Out[19]:
8
In [20]:
0b1110 ^ 0b100
Out[20]:
10
In [21]:
5 < (2+4j)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-21-4a81da7d6116> in <module>()
----> 1 5 < (2+4j)

TypeError: no ordering relation is defined for complex numbers
In [22]:
faren = raw_input("enter a value: ")
print faren
enter a value: 25
25
In [23]:
%%file number_game.py
x = 0
max_tries=10
count = 0
while True:
    x_new = int(raw_input("Enter a new number: "))
    if x_new > x:
        print " => it's bigger than the last!"
    elif x_new < x:
        print " => it's smaller than the last!"
    else:
        print " => no changes! I'll exit now"
        break
    x = x_new
    
    count += 1
    if count > max_tries:
        print "too many tries..."
        break
Writing number_game.py
In [24]:
%run number_game.py
Enter a new number: 5
 => it's bigger than the last!
Enter a new number: 8
 => it's bigger than the last!
Enter a new number: 5
 => it's smaller than the last!
Enter a new number: 5
 => no changes! I'll exit now
In [44]:
%%file breakout01.py

final_str=""
input_str=""
Done = False
while not(Done) :
    input_str=raw_input("Enter a word (. | or ? to end): ")
    final_str+=(input_str+" ")
    if input_str in ('.','!','?'):
        Done = True
        break

print final_str
Overwriting breakout01.py
In [45]:
%run breakout01.py
Enter a word (. | or ? to end): Hi
Enter a word (. | or ? to end): This
Enter a word (. | or ? to end): Is
Enter a word (. | or ? to end): Gautam
Enter a word (. | or ? to end): ?
Hi This Is Gautam ? 
In [ ]: