In [2]:
print("Hello world")


Hello world

In [4]:
1+3


Out[4]:
4

In [5]:
2*5


Out[5]:
10

In [6]:
6-7


Out[6]:
-1

In [7]:
6/3


Out[7]:
2.0

In [8]:
6//3


Out[8]:
2

In [9]:
2**3


Out[9]:
8

In [10]:
5/2


Out[10]:
2.5

In [11]:
5//2


Out[11]:
2

In [12]:
5//2.0


Out[12]:
2.0

In [13]:
5.0//2


Out[13]:
2.0

In [14]:
'This is string'


Out[14]:
'This is string'

In [16]:
"this is a dtring"


Out[16]:
'this is a dtring'

In [17]:
'''this is tripple here i can 
make a new line and it understands
up it mas mistake'''


Out[17]:
'this is tripple here i can \nmake a new line and it understands\nup it mas mistake'

In [18]:
"""  hello 
this is same as above"""


Out[18]:
'  hello \nthis is same as above'

In [19]:
True


Out[19]:
True

In [20]:
False


Out[20]:
False

In [23]:
None

In [25]:
3.5+2


Out[25]:
5.5

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


Out[24]:
'string added'

In [26]:
'1'+1


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

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

In [27]:
'a'*4


Out[27]:
'aaaa'

In [28]:
"bfdjf"-"vfkv"


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-28-67cd8b8111d3> in <module>()
----> 1 "bfdjf"-"vfkv"

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

H/W try to use all math operatrs on different types int/float/string and bool

basic operations using complex numbers


In [30]:
(2+4j)-(5+6j)


Out[30]:
(-3-2j)

In [32]:
2+4j-5+6j


Out[32]:
(-3+10j)

In [29]:
1+2j


Out[29]:
(1+2j)

variables


In [34]:
name_of_variable = 23

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

In [36]:
start


Out[36]:
0

In [37]:
end


Out[37]:
1

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


Hello

In [42]:
if start<0:
    print("negative")
elif start ==0:
    print("zero")
    print("inside the blockk")
else:
    print("positive")
    print("inside else")
print ("out of block")


zero
inside the blockk
out of block

In [43]:
if start <0 or end>1:
    print("both condition matched")
else:
    print("neither is matched")


neither is matched

In [44]:
if start == 0 and end ==1:
    print("condition matched")
else :
    print("condition not matched")


condition matched

In [45]:
2>2


Out[45]:
False

In [47]:
1<2
2>3


Out[47]:
False

In [48]:
1!=2


Out[48]:
True

In [49]:
a=2

In [50]:
1<a<3


Out[50]:
True

In [51]:
True


Out[51]:
True

In [52]:
not True


Out[52]:
False

In [53]:
a = False

In [54]:
if not a :
    print("loop executed when false")


loop executed when false

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


false

In [56]:
bool('')


Out[56]:
False

In [57]:
a = ''

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


string is empty

In [61]:
not a


Out[61]:
True

LOOPS


In [62]:
city = 'Kathmandu'

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


K
a
t
h
m
a
n
d
u

In [64]:
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 [65]:
[1,2,3]


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

In [66]:
["kathmandu", 'pokhara','butwal']


Out[66]:
['kathmandu', 'pokhara', 'butwal']

In [67]:
[1,'pp',2.5]


Out[67]:
[1, 'pp', 2.5]

In [68]:
[2,3,4,["neppal","india"]]


Out[68]:
[2, 3, 4, ['neppal', 'india']]

In [69]:
cities = ["ktm",'pokhara','butwal']

In [ ]:


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


ktm
pokhara
butwal

In [71]:
if 'ktm' in cities:
    print("yes")


yes

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


Out[75]:
True

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


true

In [77]:
range(0,9)


Out[77]:
range(0, 9)

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


0
1
2
3
4
5
6
7
8

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


0
2
4
6
8

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


0
3
6

In [87]:
for i in range(1,9):
    print(i)
    if i%5 == 0:
        break #breaks after the if statement is true


1
2
3
4
5

In [86]:
for i in range(1,9):
    
    if i%5 == 0:
        continue #continue continues to operate the loop so that when if is true it goes on
    print(i) #does not print 5 only


1
2
3
4
6
7
8

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


0
1
2
3
4

In [94]:
num = input("enter a numner:")


enter a numner:12

In [95]:
num #the input is always a string


Out[95]:
'12'

In [96]:
int(num)#type cast


Out[96]:
12

In [97]:
float(num)#type cast into float


Out[97]:
12.0

TASK 1 build a guessing game


In [1]:
from random import randint

In [2]:
const=randint(0,99)

In [ ]:
from random import randint
const=randint(0,99)
i = 0

while i<5 :
    num = input("enter your choice:")
    if int(num) > const:
        print("your number is greater")
        
    elif int(num) == const:
        print("congrats you guessed correct")
        break
    else:
        print("your number is less than required")
    i +=1
print("the correct number wasssss")
print(const)

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: