0% found this document useful (0 votes)
50 views4 pages

Python Programming Exercises

The document describes an experiment conducted by a student to write Python programs. The first program prints all twin prime numbers less than 1000, defined as two consecutive odd prime numbers. The code uses functions to check for primality and find twin primes. The second program implements formulas for permutations and combinations using functions for factorial calculations. The output screenshots show the results of running the code. The student learned about new Python topics, implementing programs, and Python syntax through this experiment.

Uploaded by

Sachin kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views4 pages

Python Programming Exercises

The document describes an experiment conducted by a student to write Python programs. The first program prints all twin prime numbers less than 1000, defined as two consecutive odd prime numbers. The code uses functions to check for primality and find twin primes. The second program implements formulas for permutations and combinations using functions for factorial calculations. The output screenshots show the results of running the code. The student learned about new Python topics, implementing programs, and Python syntax through this experiment.

Uploaded by

Sachin kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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