22MCC20041 1.1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Experiment 1.

Student Name: AMAN KUMAR UID: 22MCC20041

Branch: MCA CC&DEVOPS Section/Group: MCD-1 B

Semester: 1ST Date of Performance: 20/09/2022

Subject Name: PYTHON PROGRAMMING Subject Code: 22CAH645

1) Task to be done:

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

2) Steps for experiment/practical: copy and paste your code here/screenshots

def CheckPrime(max_num):

for num in range(2, max_num):


if max_num % num == 0:
return False
return True

# generates the list of twin primes

def TwinPrime(max_num):
for first_num in range(2, max_num):
second_num = first_num + 2

if (CheckPrime(first_num) and CheckPrime(second_num)):


print(" {0} and {1}". format(first_num, second_num))

print("TwinPrimes: ")
TwinPrime(1000)
3) Output (screenshots)
2) Task to be done:

WRITE A PROGRAM TO IMPLEMENT THESE FORMULAE OF PERMUTATIONS AND


COMBINATIONS. NUMBER OF PERMUTATIONS OF N OBJECTS TAKEN R AT A TIME: P (N, R) = N!
/ (N-R)! NUMBER OF COMBINATIONS OF N OBJECTS TAKEN R AT A TIME IS: C (N, R) = N! /
(R!*(N-R)!) = P (N, R) / R!

2) Steps for experiment/practical: copy and paste your code here/screenshots

import operator as op

# return the factorial of a number

def factorial(num):

if num == 1:
return num
return num * factorial(num-1)

# return the premutation of a number

def permutation(n, r):

return int(factorial(n) / factorial(n-r))

#returns the combinations of a number

def combination(n, r):

return int(factorial(n) / (factorial(r) * factorial(n-r)))

# print the statements

print("Permutation: ", permutation(15,4))


print("Combination: ", combination(15,4))
3) Output (screenshots)

4) Learning outcomes (What I have learnt): Times new roman 12 size


1. I HAVE LEARN NEW TOPIC OF PYTHON

2. IMPLEMENT PROGRAM

3. SYNTAX OF PYTHON CODE

Evaluation Grid:

Sr. No. Parameters Marks Obtained Maximum Marks


1. Demonstration and Performance 22
(Quiz)
2. Worksheet 8

You might also like