You are on page 1of 10

#Find the Smallest Element in an Array

a=[20, 3, 45, 67, 56, 45, 34, 1, 23]

min=a[0]

for i in range (0, len(a)):

if(a[i]<min):

min=a[i]

print(“-----------Find the smallest element in an array ---------“)

print(“The array contains.............”)

print(a)

print(“------------------------------------------------------------------“)

print(“The smallest element in the array is “, min)

print(“------------------------------------------------------------------“)
Output:

-----------Find the smallest element in an array ---------

The array contains.............

[20, 3, 45, 67, 56, 45, 34, 1, 23]

------------------------------------------------------------------

The smallest element in the array is 1

------------------------------------------------------------------
#String Functions

def disupper():

line=[]

s=raw_input(“Enter the string........:”)

if s:

line.append(s.upper())

else:

print(“NO STRING....”)

for sentence in line:

print(sentence)

def removal():

print(“Enter the string......”)

s=raw_input()

words=[word for word in s.split(“ “)]

#print “ “.join(sorted(list(set(words))))

print “ “.join(list(set(words)))

print(“--------STRING FUNCTIONS-----------“)

print(“1. Convert to UPPERCASE...........”)

print(“2. Removal of Duplicate words......”)

while True:

choice=int(input(“Enter your choice”))

if(choice==1):

disupper()
elif(choice==2):

removal()

else:

print(“Program goes to terminate......:”)

break

print(“Bye”)
Output:

--------STRING FUNCTIONS-----------

1. Convert to UPPERCASE...........

2. Removal of Duplicate words......

Enter your choice1

Enter the string......to get upper case

TO GET UPPER CASE

Enter your choice2

Enter the string......

to remove duplicate remove to this

this is duplicate remove

Enter your choice3

Program goes to terminate......:

Bye
#Program to Count the number of letters and digits

print(“--------COUNT NUMBER OF LETTERS AND DIGITS-----------“)

print(“ **************************************** “)

print(“Enter the input.................”)

s=raw_input()

d={“DIGITS”:0, “LETTERS”:0}

for c in s:

if c.isdigit():

d[“DIGITS:]+=1

elif c.isalpha():

d[“LETTERS”]+=1

else:

pass

print(“The number of LETTERS is .............:”,d[“LETTERS”])

print(“The number of DIGITS is..................:”,d[“DIGITS”])


Output

--------COUNT NUMBER OF LETTERS AND DIGITS-----------

****************************************

Enter the input.................

I ORDERED 2 cup of tea and 3 cup of coffee

The number of LETTERS is .............:30

The number of DIGITS is..................:2


#Calendar Function (Class and Object)

import calendar

def dispcal():

year =int(input(“Enter the year....:”);

calendar.prcal(year)

def dispmonth():

year1=int(input(“Enter the year.....:”)

mon1=int(input(“Enter the month.....:”)

print(calendar.month(year1,mon1))

def display():

c=calendar.TextCalendar(calendar.FRIDAY)

str=c.formatmonth(2022,4)

print(str)

print(“------------CALENDAR FUNCTIONS-------------“)

print(“1. Display the Calendar..............”)

print(“2. Display the Month.................”)

print(“3. Display particular Day as fist..”)

while True:

choice=int(input(“Enter your choice :”)

if(choice==1):

dispcal()
elif(choice==2):

dispmonth()

else:

print(“Program goes to terminate......”)

break

print(“Bye”)
Output

------------CALENDAR FUNCTIONS-------------

1. Display the Calendar..............

2. Display the Month.................

3. Display particular Day as fist..

Enter your choice :1

Enter the year....:2020

Enter the year.....:2020

Enter the month.....:1

You might also like