0% found this document useful (0 votes)
10 views3 pages

Python Programs for Basic Operations

Uploaded by

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

Python Programs for Basic Operations

Uploaded by

andersonisidorer
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PROGRAM 16:

PROGRAM DEFINITION:
Write a Python Program to convert octal number to other equivalent number.
def oct2others(n):
print("passed octal number:",n)
numstring=str(n)
decNum=int(numstring,8)
print("Number in Decimal:",decNum)
print("Number in Binary:",bin(decNum))
print("Number in Hexadecimal:",hex(decNum))
num=int(input("Enter an octal number:"))
oct2others(num)

OUTPUT:

PROGRAM 17
PROGRAM DEFINITION:
Write a program in Python to read a text file [Link] line by line and display each word separated by a #.
If [Link] contain
For every action there is equal and opposite reaction. Energy can neither be created nor be destroyed.
file1=open('[Link]','r')
for line in file1:
word=[Link]()
for i in word:
print(i,end='#')
[Link]()
output:
For#every#action#there#is#equal#and#opposite#reaction.#Energy#can#neither#be#created#nor#be#destroy
ed.#

PROGRAM 18:
PROGRAM DEFINITION:
Write a menu driven Python Program to perform Arithmetic operations (+,-*, /) based on the user’s choice.

print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
opt=int(input("Enter your choice:"))
a=int(input("Enter the First Number:"))
b=int(input("Enter the Second Number:"))
if opt==1:
c=a+b
print("The Addition of two number is:",c)
elif opt==2:
c=a-b
print("The Subtraction of two number is:",c)
elif opt==3:
c=a*b
print("The Multiplication of two number is:",c)
elif opt==4:
if b==0:
print("Enter any other number other than 0")
else:
c=a/b
print("The Division of two number is:",c)
else:
print("Invalid Option")

OUTPUT:
PROGRAM 19:
PROGRAM DEFINITION:
write a Python program to display the sum of even numbers of a list.
PROGRAM :
list = [1,2,3,4,10]
sum = 0
for i in list:
if i %2 ==0:
sum += i
print("The sum of even numbers in the list is ",sum)
output:
The sum of even numbers in the list is 16
PROGRAM 20:
PROGRAM DEFINITION:
Write a Python Program to check if a tuple contains any duplicate elements.
PROGRAM:
tup = eval(input("Enter a tuple:"))
def has_duplicates(tup):
seen = set()
for el in tup:
if el in seen:
return True
[Link](el)
return False

if has_duplicates(tup):
print("Contains duplicate elements")
else:
print("Contains no duplicate elements")

output:
Enter a tuple:3,5,7,8,12,34,2,3,13,5,2
Contains duplicate elements
Enter a tuple:4,7,9,13,24,56,3
Contains no duplicate elements

You might also like