# ---
# 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/Mugdha-Mithari/letsupgrade-python-batch7/blob/master/Assignment_1_and_2_Day_9_B7.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + id="tq0DVpHxfr9L" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 34} outputId="f0c82fc4-d512-4cba-eaad-e15080d15bfc"
#Q1.write a python function for finding it a given number prime or not
#and do Unit testing on it using Pylint & unittest library.

#Solution:

# %%writefile check_prime_number.py

def prime_number(number):
  if number > 1:
    for i in range(2, number):
      if (number % i) == 0:
        return f"Given {number} is not a prime number"
        break
      else:
        return f"Given {number} is a prime number"
  
  

num = int(7)
print(prime_number(num))




import check_prime_number

check_prime_number.prime_number(7)


# + id="pcXPO-_xgx3R" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 34} outputId="4bd27f72-281f-4ab3-e8dd-1a36662fc22a"
# %%writefile find_prime_number.py

import unittest
import check_prime_number

class test_prime_number(unittest.TestCase):
  def test_any_number(self):
    any_number = int(7)
    result = check_prime_number.prime_number(any_number)
    self.assertEquals(result, "Given 7 is a prime number")

  def testing_number(self):
    any_num = int(11)
    result = check_prime_number.prime_number(any_num)
    self.assertEquals(result, "Given 11 is a prime number")

if __name__ == "__main__":
  unittest.main()


# + id="-Eo1b39qg5YZ" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 119} outputId="a82fa3b5-6413-4353-92e2-58af14f7b6bf"
# ! python find_prime_number.py

# + id="sWKTTk6hhB5W" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 34} outputId="d0bd649f-9d1e-4314-f796-247a1c04a916"
#Q2.Make a small generator program for returning armstrong numbers 
#between 1-1000 in a generator object.

#Solution:

def armstrong_number_generator(first, last):
  for num in range(first, last + 1):
   order = len(str(num))
   sum = 0
   temp = num
   while temp > 0:
       digit = temp % 10
       sum += digit ** order
       temp //= 10

   if num == sum:
       yield (num)

Number = armstrong_number_generator(1,1000)
print(list(Number))


StarcoderdataJupyterScriptsDedupFiltered