# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/m0fauzi/BEP2073_S21/blob/main/L2_2.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + colab={"base_uri": "https://localhost:8080/"} id="I90Rm9lqUxiC" outputId="99c1bb9f-e12e-40e8-9801-a017b38daddc"
2%2

# + colab={"base_uri": "https://localhost:8080/"} id="X-GRPoW1UHq_" outputId="685f8d47-7f68-4fbc-9fb9-a6b6691d4742"
'''
QUESTION 1: Write a python program to find the 
            sum of all even numbers from 0 to 10
START
INITIALISE Ans to 0
ITERATION i less than 11
    IF i is even number
        CALCULATE Ans of i
DISPLAY Ans
END
'''
Ans = 0
for i in range(11):
  if i%2 == 0:
    # Even number
    Ans = Ans + i
print('Sum of all even number from 0 to 10 is',Ans)


# + colab={"base_uri": "https://localhost:8080/"} id="ejhIW7M5X3Ao" outputId="5d016032-faac-4d99-a102-490c52c40e42"
ans = 2 + 4 + 6 + 8 + 10
print(ans)

# + colab={"base_uri": "https://localhost:8080/"} id="KPLIJuWyZqW5" outputId="1d462af9-8ea6-413d-fa5f-84509209235e"
'''
QUESTION 2: Write a python program to read three numbers
            (a, b, c) and check how many numbers between 
            ‘a’ and ‘b’ are divisible by ‘c’
# Limit
# Consider a, b & c are integer number
# Let a < b
# Divisible operation will be resulting 0 remain
  
START
READ INPUT a, b, and c
INITIALISE count to 0
ITERATION in between a & b
    IF i/c IS divisible
        INCREASE count by 1
DISPLAY count
END
'''
#a,b,c = 1,5,2
a = int(input('a = '))
b = int(input('b = '))
c = int(input('c = '))
count = 0
for i in range(a,b+1):
  if i%c == 0:
    count += 1
print('Numbers between %d and %d are divisible by %d is %d' %(a,b,c,count))

# + colab={"base_uri": "https://localhost:8080/"} id="b0ZamTvqi5HY" outputId="fadc0ff2-d39c-4bd5-fabe-7b9ff74008c1"
'''
QUESTION 3: Write a python program to check given number is prime or not

START
DEFINE num
IF num more than 1
   ITERATION i from 2 to num
      IF num/i IS divisible
         PRINT “num is not prime number”
         BREAK
   ELSE
      PRINT “num is prime number”
ELSE
   PRINT “num is not prime number”
END
'''

num = 7
if num > 1:
  for i in range(2,num):
    if num%i == 0:
      print('%d is not prime number' %num)
      print('because %d devide %d give 0 remainder'%(num,i))

      break
  else:
    print('%d is prime number' %num) #none of i divide by num is evenly (remain = 0)
else:
  print('%d is not prime number' %num)
  print('because %d less than 0'%num)


StarcoderdataJupyterScriptsDedupFiltered