In [2]:
print("Hello world")
In [4]:
1+3
Out[4]:
In [5]:
2*5
Out[5]:
In [6]:
6-7
Out[6]:
In [7]:
6/3
Out[7]:
In [8]:
6//3
Out[8]:
In [9]:
2**3
Out[9]:
In [10]:
5/2
Out[10]:
In [11]:
5//2
Out[11]:
In [12]:
5//2.0
Out[12]:
In [13]:
5.0//2
Out[13]:
In [14]:
'This is string'
Out[14]:
In [16]:
"this is a dtring"
Out[16]:
In [17]:
'''this is tripple here i can
make a new line and it understands
up it mas mistake'''
Out[17]:
In [18]:
""" hello
this is same as above"""
Out[18]:
In [19]:
True
Out[19]:
In [20]:
False
Out[20]:
In [23]:
None
In [25]:
3.5+2
Out[25]:
In [24]:
'string '+'added'
Out[24]:
In [26]:
'1'+1
In [27]:
'a'*4
Out[27]:
In [28]:
"bfdjf"-"vfkv"
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]:
In [32]:
2+4j-5+6j
Out[32]:
In [29]:
1+2j
Out[29]:
variables
In [34]:
name_of_variable = 23
In [35]:
start, end = 0,1
In [36]:
start
Out[36]:
In [37]:
end
Out[37]:
In [38]:
if True:
print("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")
In [43]:
if start <0 or end>1:
print("both condition matched")
else:
print("neither is matched")
In [44]:
if start == 0 and end ==1:
print("condition matched")
else :
print("condition not matched")
In [45]:
2>2
Out[45]:
In [47]:
1<2
2>3
Out[47]:
In [48]:
1!=2
Out[48]:
In [49]:
a=2
In [50]:
1<a<3
Out[50]:
In [51]:
True
Out[51]:
In [52]:
not True
Out[52]:
In [53]:
a = False
In [54]:
if not a :
print("loop executed when false")
In [55]:
if a:
print("true")
else:
print("false")
In [56]:
bool('')
Out[56]:
In [57]:
a = ''
In [60]:
if not a:
print("string is empty")
In [61]:
not a
Out[61]:
LOOPS
In [62]:
city = 'Kathmandu'
In [63]:
for char in city:
print(char)
In [64]:
for i in range(0,len(city)):
print(city[i],i)
In [65]:
[1,2,3]
Out[65]:
In [66]:
["kathmandu", 'pokhara','butwal']
Out[66]:
In [67]:
[1,'pp',2.5]
Out[67]:
In [68]:
[2,3,4,["neppal","india"]]
Out[68]:
In [69]:
cities = ["ktm",'pokhara','butwal']
In [ ]:
In [70]:
for city in cities:
print(city)
In [71]:
if 'ktm' in cities:
print("yes")
In [75]:
'k' in 'kathmandu'
Out[75]:
In [76]:
for char in 'kathmandu':
if char == 'k':
print("true")
In [77]:
range(0,9)
Out[77]:
In [78]:
for i in range(0,9):
print(i)
In [80]:
for i in range (0,9):
if i%2 ==0:
print(i)
In [83]:
for i in range (0,9,3):
print (i)
In [87]:
for i in range(1,9):
print(i)
if i%5 == 0:
break #breaks after the if statement is true
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
In [93]:
i = 0
while True:
if i==5:
break
print(i)
i +=1
In [94]:
num = input("enter a numner:")
In [95]:
num #the input is always a string
Out[95]:
In [96]:
int(num)#type cast
Out[96]:
In [97]:
float(num)#type cast into float
Out[97]:
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 [ ]: