PROGRAM
PROGRAM
list1=list1.split(',')
# sorting the list
list1.sort()
PROGRAM-54
#Program to have an increment of 10 to each element of list
#Saurish Seth
#class-11A
#roll number-19
def increment(ListA):
for i in range(0,len(ListA)):
ListA[i]+=10 #Adding 10 to each element
return ListA
ListA=[1,8,9,52,67]
ListA=increment(ListA)
print(ListA)
count=morethan(List2)
print('Number of children who have gotten more than 70 marks are:',count)
PROGRAM-56
#Program to swap elements of the list
#Saurish Seth
#class-11A
#roll number-19
def swap_adjacent_elements(lst):
for i in range(0, len(lst)-1, 2):
lst[i], lst[i+1] = lst[i+1], lst[i]
PROGRAM-57
#Program to half even and double odd elements
#Saurish Seth
#class-11A
#roll number-19
def half_even_double_odd(input_list):
result_list = []
for num in input_list:
if num % 2 == 0:
result_list.append(num / 2)
else:
result_list.append(num * 2)
return result_list
input_numbers = [1, 2, 3, 4, 5, 6]
result = half_even_double_odd(input_numbers)
print("Input List:", input_numbers)
print("Result List:", result)
PROGRAM-58
#program to show bubblesort
def bubblesort(theSeq):
n=len(theSeq)
for i in range(n-1):
flag=0
for j in range(n-1):
if theSeq[j]>theSeq[j+1]:
tmp=theSeq[j]
theSeq[j]=theSeq[j+1]
theSeq[j+1]=tmp
flag=1
if flag==0:
break
return theSeq
el=[21,6,9,33,3]
print('Unsorted array:',el)
result=bubblesort(el)
print('Sorted Array:',result)
Unsorted array: [21, 6, 9, 33, 3]
Sorted Array: [3, 6, 9, 21, 33]
PROGRAM-59
#Program to count the number of vowels in a string using concepts of lists
#Saurish Seth
#class-11A
#roll number-19
str=input("Enter a string:")
vowels=['a','e','i','o','u','A','E','I','O','U'] #list of vowels
wordlist=str.split(" ")
count=0 #initial count
for word in wordlist:
for i in range(len(word)):
if word[i] in vowels:
#increasing the count by 1
count+=1
print("Number of vowels in the string are:",count)
PROGRAM-60
#Program to calculate the cost of tent
#Saurish Seth
#class-11A
#roll number-19
#function definition
def cyl(h,r):
area_cyl = 2*3.14*r*h #Area of cylindrical part
return(area_cyl)
#function definition
def con(l,r):
area_con = 3.14*r*l #Area of conical part
return(area_con)
#function definition
def post_tax_price(cost): #compute payable amount for the tent
tax = 0.18 * cost;
net_price = cost + tax
return(net_price)
print("Enter values of cylindrical part of the tent in meters:")
h = float(input("Height: "))
r = float(input("Radius: "))
csa_cyl = cyl(h,r) #function call
l = float(input("Enter slant height of the conical area in meters: "))
csa_con = con(l,r) #function call
#Calculate area of the canvas used for making the tent
canvas_area = csa_cyl + csa_con
print("Area of canvas = ",canvas_area," m^2")
#Calculate cost of canvas
unit_price = float(input("Enter cost of 1 m^2 canvas in rupees: "))
total_cost = unit_price * canvas_area
print("Total cost of canvas before tax = ",total_cost)
print("Net amount payable (including tax) = ",post_tax_price(total_cost))
PROGRAM-61
#Program to take two numbers from the user and printing their sum
#Saurish Seth
#class-11A
#roll number-19
#function definition
def sum(num1,num2):
their_sum=num1+num2 #finding their sum by adding them
return their_sum
#driver code
#taking input of the two numbers from the user
num1=int(input("Enter the first number:"))
num2=int(input("Enter the second number:"))
their_sum=sum(num1,num2) #assigning the result to the variable
print('The sum if the numbers is :',their_sum)
PROGRAM-62
#Program to find sum of the first n natural numbers
#Saurish Seth
#class-11A
#roll number-19
def nsum(n):
sum=0
for i in range(1,n+1):
sum+=i
return sum
#Driver code
#taking inputs
n=int(input("Enter the number till the sum has to be taken:"))
sum=nsum(n)
print('The sum of n numbers is:',sum)
PROGRAM-63
#Program to add an increment of 5 to nunber and printing the id before and after
the increment
#Saurish Seth
#class-11A
#roll number-19
def increment(num):
print('Number is',num)
print('id of the number before increment',id(num)) #id of the number
before increment
num+=5
return num
num=int(input("Enter a number:"))
num=increment(num)
print('Number after increment by 5 is',num)
print('id of the number after increment is',id(num))
PROGRAM-64
#Program to input names and print the full name
#Saurish Seth
#class-11A
#roll number-19
def f_name(firs_name,last_name):
full_name=firs_name+' '+last_name #using concatenation
return full_name
PROGRAM-65
#Program to print mixed fraction where the value of denominator is fixed as 1
def mixedfraction(num,deno=1):
remainder=num%deno
quotient=int(num/deno)
if remainder!=0:
PROGRAM-66
#Program to print exponential value of the number entered
#Saurish Seth
#class-11A
#roll number-19
def POWER(x,y):
z=1
for i in range(1,y+1):
z=x*z
return z
#Driver code
x=int(input("Enter the base value:"))
y=int(input("Enter the exp value:"))
result=POWER(x,y)
print('The exponential value is:',result)
PROGRAM-68
#Program to print name and other details of the students
st=((101,"Aman",98),(102,"Raj",91),(103,"Kiara",99),(104,"Timsy",84))
print('S.no','\tRoll no','Name','\tMarks')
for i in range(0,len(st)):
print((i+1),'\t',st[i][0],'\t',st[i][1],'\t',st[i][2])
S.no Roll no Name Marks
1 101 Aman 98
2 102 Raj 91
3 103 Kiara 99
4 104 Timsy 84
PROGRAM-69
#Program to give values to given traffic lights
#Saurish Seth
#class-11A
#roll number-19
def trafficLight():
signal = input("Enter the colour of the traffic light: ")
if (signal not in ("RED","YELLOW","GREEN")):
print("Please enter a valid Traffic Light colour in
CAPITALS")
else:
value = light(signal) #function call to light()
if (value == 0):
print("STOP, Your Life is Precious.")
elif (value == 1):
print ("PLEASE GO SLOW.")
else:
print("GO!,Thank you for being patient.")
#function ends here
def light(colour):
if (colour == "RED"):
return(0);
elif (colour == "YELLOW"):
return (1)
else:
return(2)
#function ends here
trafficLight()
print("SPEED THRILLS BUT KILLS")
PROGRAM71
#Program to find area and circumference of the circle using user-defined
functions
def circle(r):
area=3.14*r*r
circum=2*3.14*r
return (area,circum)
#Driver Code
r=eval(input("Enter the radius of the circle in meters:"))
area,circum=circle(r)
print('Area of the circle is:',area)
print('Circumference if the circle is:',circum)
============ RESTART: /Users/saurish/Desktop/Q1.py ===========
Enter the radius of the circle in meters:5
Area of the circle is: 78.5
Circumference if the circle is: 31.400000000000002
PROGRAM-72
#Program to take n numbers from the user and printing the maximum and the
minimum number
numbers=tuple()
n=int(input("Enter how many numbers you want to input:"))
for i in range(0,n):
num=int(input())
numbers=numbers+(num,)
print('The entered numbers are:')
print(num)
print('\nThe max number is:')
print(max(numbers))
print('\nThe min number is:')
print(min(numbers))
=========== RESTART: /Users/saurish/Desktop/Q1.py ===========
Enter how many numbers you want to input:4
enter5
enter6
enter3
enter9
The entered numbers are:
9
EMPLOYEE_NAME SALARY
a 5
b 7
PROGRAM-75
#Program to enter number and its value in words
#Creating a user defined function
def inwords(num):
numnames={0:'Zero',1:'One',2:'Two',3:'Three',4:'Four',5:'Five',6:'Six',7:'S
even',8:'Eight',9:'Nine'}
==============================================================
RESTART: /Users/saurish/Desktop/Q1.py
=============================================================
Enter the number of students: 2
Enter email ID for student 1: jrh@gmail.com
Enter email ID for student 2: wurkuewef@gmail.com
=============================================================
RESTART: /Users/saurish/Desktop/Q1.py
=============================================================
Dictionary: {'Alice': 90, 'Bob': 85, 'Charlie': 95, 'David': 88, 'Eve': 92}
#Saurish Seth
#class-11A
#roll number-19
def display_friends(dictionary):
print("\nFriends and their Phone Numbers:")
for name, phone in dictionary.items():
print(f"{name}: {phone}")
def display_sorted(dictionary):
sorted_dict = dict(sorted(dictionary.items()))
print("\nDictionary in sorted order of names:")
display_friends(sorted_dict)
def main():
friends_dict = {}
while True:
print("\nOperations:")
print("a) Display friends and phone numbers")
print("b) Add a new friend")
print("c) Delete a friend")
print("d) Modify phone number")
print("e) Check if a friend is present")
print("f) Display sorted dictionary")
print("x) Exit")
if choice == 'a':
display_friends(friends_dict)
elif choice == 'b':
name = input("Enter friend's name: ")
phone = input("Enter friend's phone number: ")
add_friend(friends_dict, name, phone)
elif choice == 'c':
name = input("Enter the name of the friend to
delete: ")
delete_friend(friends_dict, name)
elif choice == 'd':
name = input("Enter the name of the friend to
modify: ")
new_phone = input("Enter the new phone number: ")
modify_phone(friends_dict, name, new_phone)
elif choice == 'e':
name = input("Enter the name of the friend to check:
")
check_friend(friends_dict, name)
elif choice == 'f':
display_sorted(friends_dict)
elif choice == 'x':
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()
==============================================================
RESTART: /Users/saurish/Desktop/Q1.py
=============================================================
Operations:
a) Display friends and phone numbers
b) Add a new friend
c) Delete a friend
d) Modify phone number
e) Check if a friend is present
f) Display sorted dictionary
x) Exit
Enter your choice: a
Operations:
a) Display friends and phone numbers
b) Add a new friend
c) Delete a friend
d) Modify phone number
e) Check if a friend is present
f) Display sorted dictionary
x) Exit
Enter your choice: b
Enter friend's name: b
Enter friend's phone number: 986723
Friend added successfully.
Operations:
a) Display friends and phone numbers
b) Add a new friend
c) Delete a friend
d) Modify phone number
e) Check if a friend is present
f) Display sorted dictionary
x) Exit
Enter your choice: c
Enter the name of the friend to delete: c
Operations:
a) Display friends and phone numbers
b) Add a new friend
c) Delete a friend
d) Modify phone number
e) Check if a friend is present
f) Display sorted dictionary
x) Exit
Enter your choice: d
Enter the name of the friend to modify: alice
Enter the new phone number: 7262626262
Operations:
a) Display friends and phone numbers
b) Add a new friend
c) Delete a friend
d) Modify phone number
e) Check if a friend is present
f) Display sorted dictionary
x) Exit
Enter your choice: e
Enter the name of the friend to check: alice
Operations:
a) Display friends and phone numbers
b) Add a new friend
c) Delete a friend
d) Modify phone number
e) Check if a friend is present
f) Display sorted dictionary
x) Exit
Enter your choice: f
Operations:
a) Display friends and phone numbers
b) Add a new friend
c) Delete a friend
d) Modify phone number
e) Check if a friend is present
f) Display sorted dictionary
x) Exit
Enter your choice: x