Monday, July 25, 2011

Python If then else

කොටුව තුළ දීඇති පයිතන් ක‍්‍රමලේඛයේ ප‍්‍රතිදානය කුමක් ද?

j=10
y=4
if j<y or j!=4:
    j-=y
    print j
else:
    y*=j
   print y

(1) 4
(2) 6
(3) 10
(4) 14
(5) 40

Python 3.0

j=10
y=4
if ((j<y) or (j!=4)):
    j-=y
    print (j)
else:
    y*=j 
    print (y)


==================

if, elif, and else program branches

mark=float(raw_input("Please enter a mark"))
if mark >= 40:
  print "You passed."
  print "Well done."
else:
  print "You failed."
  print "too bad."
-----------------



age = 17

if age > 18:
   print "Driving licence issued"
else:
   print "Driving licence not permitted"
if (age >= 12) or (age < 18)):
 print "teen"
else :
if  (age < 12) : 
print "kid"
     else:
          print "adult

Comparing data values
None The null object
0 Integer zero 0
0 Floating point zero
"" Empty strings
{} Empty dictionaries
[] Empty lists
() Empty tuples

magic=input("Enter No ? ")

if not (magic == 8 or magic == 9 or magic ==10 ) :
  print '"Time for Tea", said Boss '
else:
  print '"No Tea !" said Boss'



No comments:

Post a Comment