In [1]:
print("hello world")


hello world

In [2]:
1+2


Out[2]:
3

In [3]:
2*4


Out[3]:
8

In [4]:
5-6


Out[4]:
-1

In [5]:
4-2


Out[5]:
2

In [6]:
6/3


Out[6]:
2.0

In [7]:
6//2


Out[7]:
3

In [8]:
5/2


Out[8]:
2.5

In [9]:
5//2


Out[9]:
2

In [10]:
6%3


Out[10]:
0

In [11]:
4**2


Out[11]:
16

In [12]:
5//2.0


Out[12]:
2.0

In [13]:
5.0/2


Out[13]:
2.5

In [14]:
'this is a string'


Out[14]:
'this is a string'

In [15]:
"this is also a string"


Out[15]:
'this is also a string'

In [16]:
"'this is triple quoted string'"


Out[16]:
"'this is triple quoted string'"

In [17]:
"'this
is''"


  File "<ipython-input-17-2ad36a174689>", line 1
    "'this
          ^
SyntaxError: EOL while scanning string literal

In [18]:
"""this
is"""


Out[18]:
'this\nis'

In [19]:
"'this 
is"


  File "<ipython-input-19-bfec1a3a44d0>", line 1
    "'this
           ^
SyntaxError: EOL while scanning string literal

In [20]:
true


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-20-74d9a83219ca> in <module>()
----> 1 true

NameError: name 'true' is not defined

In [21]:
True


Out[21]:
True

In [22]:
False


Out[22]:
False

In [24]:
None

In [25]:
'string' +'added'


Out[25]:
'stringadded'

In [26]:
'1'+'1'


Out[26]:
'11'

In [27]:
'1'+1


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-27-0b5599e2e487> in <module>()
----> 1 '1'+1

TypeError: Can't convert 'int' object to str implicitly

In [28]:
a=2

In [29]:
'a'*4


Out[29]:
'aaaa'

In [30]:
'string'-'str'


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-30-6a3a405c8605> in <module>()
----> 1 'string'-'str'

TypeError: unsupported operand type(s) for -: 'str' and 'str'

h/w try to use all the math operators on different types of string/int/boolean/float


In [31]:
1+2j


Out[31]:
(1+2j)

2+4j-5+6j


In [32]:
(2+4j)+(3+3j)


Out[32]:
(5+7j)

In [33]:
2+4j-5+2j


Out[33]:
(-3+6j)

In [34]:
conditionals


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-34-54d51d86716a> in <module>()
----> 1 conditionals

NameError: name 'conditionals' is not defined

VARIABLES


In [ ]:
name_of _variable = 23

In [ ]:
'NAMING OF A VARIABLE''a-zA-Z_0-9'

In [ ]:
leapfrog_wifi=3 'for python:snake case all small undescore'

In [ ]:
LeapFrogWifi=3"camel case"

In [ ]:
leapFrogWifi=3'capital case'

In [35]:
start, end=0, 1

In [36]:
start


Out[36]:
0

In [37]:
end


Out[37]:
1

CONDITIONALS


In [38]:
if True:
    print("heyy")


heyy

In [44]:
if (start<0):
    print("this is negative")
elif start==0:
    print("it is  zero")
else:
    print("greater than zero")
print("hey there im out of block")


it is  zero
hey there im out of block

In [ ]:
if end=1:
    print("found end")

In [45]:
if start<0 or end>1:
    print("start is 0 end is 1")
else:
    print("neither")


neither

In [46]:
if start==0 and end==1:
    print("and")


and

In [47]:
2>1


Out[47]:
True

In [48]:
start==1


Out[48]:
False

In [49]:
a=2

In [50]:
1<a<3


Out[50]:
True

In [51]:
1<=2


Out[51]:
True

In [52]:
1!=2


Out[52]:
True

In [53]:
1==2


Out[53]:
False

In [54]:
True


Out[54]:
True

In [55]:
not True


Out[55]:
False

In [56]:
a= False

In [57]:
if not a:
    print("a is false")


a is false

In [58]:
if !a:
    print("false")


  File "<ipython-input-58-a90dac5174cf>", line 1
    if !a:
       ^
SyntaxError: invalid syntax

In [60]:
if a:
    print("true")
else:
    print("false")


false

In [61]:
a=''

In [62]:
if not a:
    print("string empty")
if a:
    print("string is nt empty")


string empty

In [63]:
not a


Out[63]:
True

LOOPS


In [65]:
city= 'Kathmandu'

In [ ]:


In [66]:
for char in city:
    print(char)


K
a
t
h
m
a
n
d
u

In [67]:
for i in range(0,len(city)):
    print (city[i],i)


K 0
a 1
t 2
h 3
m 4
a 5
n 6
d 7
u 8

In [69]:
for i in range(0,9):
    print(city[i],i)


K 0
a 1
t 2
h 3
m 4
a 5
n 6
d 7
u 8

In [70]:
[1,2,3]


Out[70]:
[1, 2, 3]

In [71]:
['chitwan','kathmandu','pokhara']


Out[71]:
['chitwan', 'kathmandu', 'pokhara']

LISTS


In [ ]:


In [72]:
[1,'p',2.546]


Out[72]:
[1, 'p', 2.546]

In [73]:
[2,3,4,[2,3,4]]


Out[73]:
[2, 3, 4, [2, 3, 4]]

In [74]:
cities=['chitwan','pokhara','kathmandu']

In [75]:
for city in cities:
    print(city)


chitwan
pokhara
kathmandu

In [76]:
if'kathmandu' in cities:
    print("yes")


yes

In [77]:
'k'in 'kathmandu'


Out[77]:
True

In [78]:
for char in 'kathmandu':
    if char=='k':
        print('true')


true

In [79]:
range(0,9)


Out[79]:
range(0, 9)

In [80]:
for i in range (0,9):
    print(i)


0
1
2
3
4
5
6
7
8

In [81]:
for i in range(0,9):
    if i%2 == 0:
        print(i)


0
2
4
6
8

In [82]:
for i in range (0,9,2):
    print(i)


0
2
4
6
8

In [84]:
for i  in range (0,9,4):
    print(i)


0
4
8

In [85]:
for i in range (1,9):
    print(i)
    if i %5 == 0:
        break


1
2
3
4
5

In [86]:
for i in range (1,9):
    if i%5==0:
        break
    print (i)


1
2
3
4

In [88]:
for i in range (1,9):
    
    if i%5==0:
        print(i)
        continue


5

In [89]:
#it is a comment.

In [90]:
i=0
while True:
    if i==5:
        break
    print(i)
    i+=1


0
1
2
3
4

In [91]:
num= input ("enter a nummber")


enter a nummber2

In [92]:
num


Out[92]:
'2'

In [93]:
int (num)


Out[93]:
2

In [94]:
float(num)


Out[94]:
2.0

In [95]:
num +2


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-95-aead9acb0cef> in <module>()
----> 1 num +2

TypeError: Can't convert 'int' object to str implicitly

BUILD A GUESSING GAME


In [96]:
from random import randint

In [99]:
randint(0,99)


Out[99]:
37

In [ ]:
from random import randint
b= randint(1,99)
print("lets start the game!!!")
i=1
while i<4:
    a= input("enter a number between 1 to 100")
    c= int(a)
    if c<b:
        print("number is slightly less")
    elif c>b:
        print("number is greater")
    else:
        print("correct guess")
        print(b)
        break
    i+=1

In [ ]:
from random import randint
b= randint(1,99)
print("lets start the game!!!")
i=1
while i<4:
    a= input("enter a number between 1 to 100")
    c= int(a)
    if c==b:
        print("correct guess")
        print(b)
        break
    elif c<b:
        print("number is slightly less")
    else:
        print("number is greater")
    
    i+=1

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: