lundi 21 septembre 2015

4 lines of python codes. have no clue why it prints out such output

I have five python program in 3-5 lines of code. Just wondering why each of them prints out such output. or what output they print out and hwy. I would appreciate your feedback on this!

1. for j in xrange(10,40,5):
       if j % 3 != 0:
            print j
OUTPUT: 10
        20
        25
        35

2. count = 0
    for char in "ABC 123":
        if not char == '3':
           count += 1
    print count

OUTPUT: 5

3. true, false = Fase, True
   if not true:
        print "True is", true
   else:
        print "False is", false

4. for x in [1, 1, 2, 3, 5, 8, 13]:
   if 1<x<13:
       continue
       else:
         print x

5. found = False
   for n in xrange(40,50):
      if (n / 45) > 1:
         found = True
         break
   print found

OUTPUT: 5

Aucun commentaire:

Enregistrer un commentaire