IF - ELSE and WHILE Practice

  1. What will be the output of the following code fragment
    num = 6
    counter = 0
    while ( counter <= 6):

    if num % 2 == 0:
      print num

    counter = counter + 1

  2. What is the output of the following program, if the input was: 5 -4 6 -7 8?
    num = 5
    counter = 0
    while (counter < num):

    current = input ("Please enter the number ")
    if current < 0:
      print current

    counter = counter + 1

  3. What will be the output of the following program, if the input was
    1 -3 4 5 -9 7 0?


    a = 1
    sum = 0
    while a != 0:

    a = input ("enter the number ")
    if a > 0:
      sum = sum + a

    print "sum is ", sum

  4. Write the program printPos.py that will read 10 numbers and print all positive numbers.