Function Assignment PDF
Function Assignment PDF
Write a function that inputs a number and prints the multiplication table of that number
2.Write a program to print twin primes less than 1000. If two consecutive odd numbers are
both prime then they are known as twin primes
def generate_twins(n):
for i in range(1, n):
j = i + 2
if(is_prime(i) and is_prime(j)):
print("{:d} and {:d}".format(i, j))
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Enter the maximum number:100
1 and 3
3 and 5
5 and 7
11 and 13
17 and 19
29 and 31
41 and 43
59 and 61
71 and 73
3. Write a program to find out the prime factors of a number. Example: prime factors of 56
- 2, 2, 2, 7
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
if n>=1:
dec2bin(n/2)
print(int(n%2),end='')
6. Write a function cubesum() that accepts an integer and returns the sum of the cubes of
individual digits of that number. Use this function to make functions PrintArmstrong() and
isArmstrong() to print Armstrong numbers and to find whether is an Armstrong number.
def PrintArmstrong(old_number):
print(old_number, "is Prime.")
def general_sum(n):
summ = 0
rem = 0
count = 0
original = n
n1 = n
while n1!= 0:
n1 = int(n1/10)
count = int(count +1)
while n!=0:
rem = int(n%10)
n = int(n/10)
summ = summ + (rem**count)
isArmstrong(summ,original)
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Enter the number:372
Number is not Prime
7. Write a function prodDigits() that inputs a number and returns the product of digits of
that number.
8. If all digits of a number n are multiplied by each other repeating with the product, the
one digit number obtained at last is called the multiplicative digital root of n. The number
of times digits need to be multiplied to reach one digit is called the multiplicative
persistance of n. Example: 86 -> 48 -> 32 -> 6 (MDR 6, MPersistence 3) 341 -> 12->2 (MDR
2, MPersistence 2) Using the function prodDigits() of previous exercise write functions
MDR() and MPersistence() that input a number and return its multiplicative digital root and
multiplicative persistence respectively
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
print(n1)
def Digit_Count(n):
n1=n
print(n1,end='')
count = 0
while n!=0:
n = int(n/10)
count = count + 1
prodDigit(n1,count)
9. Write a function sumPdivisors() that finds the sum of proper divisors of a number.
Proper divisors of a number are those numbers by which the number is divisible, except
the number itself. For example proper divisors of 36 are 1, 2, 3, 4, 6, 9, 18
10. A number is called perfect if the sum of proper divisors of that number is equal to the
number. For example 28 is perfect number, since 1+2+4+7+14=28. Write a program to print
all the perfect numbers in a given range
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
if original_number%number_to_be_checked == 0:
properDivisor(original_number,(number_to_be_checked-1))
print(number_to_be_checked)
def func(n):
properDivisor(n,int(n/2))
for i in range(1,int(n/2)+1):
if n%i==0:
summ = summ + i
if summ==n:
print(n,"is perfect number.")
else:
print(n,"is not perfect number.")
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD