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

NM Python Project List

The document contains multiple Python programs demonstrating various functionalities such as basic arithmetic operations, finding duplicate numbers, intersecting arrays, identifying the first unique character, reversing vowels in a string, and generating twin primes. Each program includes input prompts, processing logic, and output examples. The programs showcase fundamental programming concepts and data structures in Python.

Uploaded by

23331
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)
5 views4 pages

NM Python Project List

The document contains multiple Python programs demonstrating various functionalities such as basic arithmetic operations, finding duplicate numbers, intersecting arrays, identifying the first unique character, reversing vowels in a string, and generating twin primes. Each program includes input prompts, processing logic, and output examples. The programs showcase fundamental programming concepts and data structures in Python.

Uploaded by

23331
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

Program 4 Number of Operations

num1 = int(input('Enter First number: '))


num2 = int(input('Enter Second number '))
add = num1 + num2
dif = num1 - num2
mul = num1 * num2
div = num1 / num2
floor_div = num1 // num2
power = num1 ** num2
modulus = num1 % num2
print('Sum of ',num1 ,'and' ,num2 ,'is :',add)
print('Difference of ',num1 ,'and' ,num2 ,'is :',dif)
print('Product of' ,num1 ,'and' ,num2 ,'is :',mul)
print('Division of ',num1 ,'and' ,num2 ,'is :',div)
print('Floor Division of ',num1 ,'and' ,num2 ,'is :',floor_div)
print('Exponent of ',num1 ,'and' ,num2 ,'is :',power)
print('Modulus of ',num1 ,'and' ,num2 ,'is :',modulus)
OUTPUT
Enter First number: 56
Enter Second number 6
Sum of 5 and 6 is : 11
Difference of 5 and 6 is : -1
Product of 5 and 6 is : 30
Division of 5 and 6 is : 0.8333333333333334
Floor Division of 5 and 6 is : 0
Exponent of 5 and 6 is : 15625
Modulus of 5 and 6 is : 5
************************************************************************
Program 5 Duplicate Number
l=[1,2,3,4,5,2,3,4,7,9,5]
l1=[]
for i in l:
if i not in l1:
l1.append(i)
else:
print(i,end=' ')
OUTPUT
2345
************************************************************************
Program 6 Intersection of two arrays
class Solution(object):
def intersect(self, nums1, nums2):
"""
:type nums1: List[int]
:type nums2: List[int]
:rtype: List[int]
"""
m = {}
if len(nums1)<len(nums2):
nums1,nums2 = nums2,nums1
for i in nums1:
if i not in m:
m[i] = 1
else:
m[i]+=1
result = []
for i in nums2:
if i in m and m[i]:
m[i]-=1
result.append(i)
return result
ob1 = Solution()
print(ob1.intersect([1,4,5,3,6], [2,3,5,7,9]))
OUTPUT
[3, 5]
******************************************************************

Program 7 First Unique Character


def firstUniqueChar(s):
from collections import Counter
count = Counter(s)
for i , j in enumerate(s):
if count[j] == 1:
return i
else:
return -1
print(firstUniqueChar("madam"))

OUTPUT
2
***********************************************************************
Program 8 Reverse Vowels

def reverseString(s):
vowels = ""
for char in s:
if char in "aeiouAEIOU":
vowels += char
result_string = ""
for char in s:
if char in "aeiouAEIOU":
result_string += vowels[-1]
vowels = vowels[:-1]
else:
result_string += char
return result_string
print(reverseString("JavaTpoint"))

OUTPUT
ssbcellego
******************************************************************

Program 9 Twin Prime

def is_prime(n):
for i in range(2, n):
if n % i == 0:
return False
return True

def generate_twins(start, end):


for i in range(start, end):
j=i+2
if(is_prime(i) and is_prime(j)):
print("{:d} and {:d}".format(i, j))

generate_twins(2, 100)

OUTPUT
3 and 5
5 and 7
11 and 13
17 and 19
29 and 31
41 and 43
59 and 61
71 and 73
*********************************************************************

You might also like