0% found this document useful (0 votes)
154 views71 pages

Computer Science: Practical Record File Term - I & Ii

The document contains a practical record file for the subject Computer Science for a student named Hemanth Bendone Venkatesha of class XI. It includes 44 programs written by the student on various topics like calculating x to the power n, simple interest, checking even/odd numbers, finding the day of the week etc. along with their input and output. The file also has an index listing the program number and topic and signatures of the internal and external examiners.

Uploaded by

Hemanth
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)
154 views71 pages

Computer Science: Practical Record File Term - I & Ii

The document contains a practical record file for the subject Computer Science for a student named Hemanth Bendone Venkatesha of class XI. It includes 44 programs written by the student on various topics like calculating x to the power n, simple interest, checking even/odd numbers, finding the day of the week etc. along with their input and output. The file also has an index listing the program number and topic and signatures of the internal and external examiners.

Uploaded by

Hemanth
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
You are on page 1/ 71

DELHI PUBLIC SCHOOL MYSORE

2021-2022

COMPUTER SCIENCE
(083)

PRACTICAL RECORD FILE


TERM – I & II

NAME: HEMANTH BENDONE VENKATESHA

CLASS: XI SEC A

ROLL NUMBER: 08
DELHI PUBLIC SCHOOL, MYSORE

CERTIFICATE

This is to certify that _______________________________ of class


XI bearing Board examination Roll No. __________________ has
successfully completed practical record file during the academic year
2021-2022 in partial fulfillment of Term – II practical examination for
the subject COMPUTER SCIENCE (083) conducted by AISSCE,
CBSE

Date:

Internal Examiner Principal Signature

External Examiner
INDEX – TERM 1 & 2
Sn.No Program Page No.
1 To compute xn of given two integers x and n 1
2 Calculating simple interest 2
3 Even or odd number 3
4 Day of the week 4,5
5 Leap year 6
6 Calculator with basic functions(+,-,*,/) 7,8
7 Check a character 9
8 Largest and smallest number 10,11
9 Percentage of a student 12,13
10 Sum and product of first n natural numbers 14
11 Sum of first n even and odd numbers 15
12 Factors of a given number 16
13 Divisible by a number Num 17
14 Series 1,3,5,7,9…N 18
15 Series 1,8,27,64,125…N 19
16 Count number of +ve, -ve and even numbers 20,21
17 Palindrome 22
18 Fibonacci series 23,24
19 Prime numbers 25
20 Armstrong number 26
21 Series 1+x1/1!+x2/2!+...xn/n! [Exponential series] 27
22 Palindrome(string) 28
23 Capital letter 29,30
24 Count number of different types of characters 31,32,33
25 Menu driven program 34,35
26 Menu driven program on lists 36-39
27 Linear search 40
28 Sum and the average of list 41
29 Sorting 42
30 Replace 10 by 100 43
31 String to a list 44
32 Sum of the elements of both sides 45
33 Rotating list 46
34 Even and odd elements into lists 47
35 Longest word in the list 48
36 List to tuple 49
37 Remove an item from a tuple 50
38 Find the index 51
39 Unpacking a tuple 52
40 Reverse a tuple 53
41 Find the shortest string in a tuple 54
42 Accept marks of five students 55,56
43 Sentence to dictionary 57
44 Wins and loses of a team 58-60
45 Product name and prices 61,62
46 Reversing keys and values 63
47 Overlapping 2 dictionaries 64
48 Month and days of a year 65-67
Q1) WAP to compute xn of given two integers x and n.

Input-
x=int(input(" enter a no. x: "))
n=int(input(" enter a no. n: "))
t=x**n
print(" the value of x^n is ",t)

Output-
enter a no. x: 5
enter a no. n: 4
the value of x^n is 625

1
Q2) WAP for calculating simple interest.

Input-
p=int(input("enter the principal amount p:"))
r=int(input("enter the rate of interest r:"))
t=int(input("enter the time t:"))
sp=(p*r*t)/100
print("the simple interest is",sp)

Output-
enter the principal amount p:5000
enter the rate of interest r:5
enter the time t:4
the simple interest is 1000.0

2
Q3) WAP to accept a number from the user and display whether it
is an even number or Odd number.

Input-
n=int(input("enter a number n:"))
rem=n%2
if rem==0 :
print("n is a even number")
else:
print("n is a odd number")

Output-
I.) enter a number n:5
n is a odd number
II.) enter a number n:4
n is a even number

3
Q4) WAP to accept the day of the week from the user and print the
day of the week.

Input-
weekday = int(input("Enter weekday number : "))
if weekday == 1 :
print("Monday");
elif weekday == 2 :
print("Tuesday")
elif(weekday == 3) :
print("Wednesday")
elif(weekday == 4) :
print("Thursday")
elif(weekday == 5) :
print("Friday")
elif(weekday == 6) :
print("Saturday")
elif (weekday == 7) :
print("Sunday")
else :
4
print("Number beyond 7 not acceptable.")

Output-
Enter weekday day number : 5
Friday

5
Q5) WAP to check whether the given year is leap year or not.
Input-
year=int(input("Enter a year:"))
if (year % 4) == 0:
if (year % 100) == 0:
if (year % 400) == 0:
print("year",year,"is a leap year")
else:
print("year",year,"is not a leap year")

Output-
I.) Enter a year: 2021
year 2021 is not a leap year
II.) Enter a year: 2020
year 2020 is a leap year

6
Q6) WAP to take accept two numbers and operator from the user
and create a menu to provide four functions of a calculator
(+,- ,* , /)
Input-
print("1.add")
print("2.subtract")
print("3.multiply")
print("4.divide")
choice = input("Enter choice:")
n1=int(input("enter a number 1:"))
n2=int(input("enter a number 2:"))
if choice=='1':
print(n1, "+", n2, "=", (n1+n2))
elif choice=='2':
print(n1, "-", n2, "=", (n1-n2))
elif choice=='3':
print(n1, "*", n2, "=", (n1*n2))
elif choice=='4':
print(n1, "/", n2, "=", (n1/n2))
else:
print("Invalid Input")
7
Output-
Enter choice:3
enter a number 1:5
enter a number 2:4
5 * 4 = 20

8
Q7) WAP to accept a character from the user and check whether it
is a letter, digit, space, or a special character.

Input-
ch=input("enter a chartarter:")
if((ch>='a' and ch<='z') or(ch>='A' and ch<='Z')):
print(ch,"is a letter")
elif(ch>='0' and ch<='9'):
print(ch,"is a digit")
elif(ch==' '):
print(ch,"is a space")
else:
print(ch,"is a special character")

Output-
enter a chartarter:5
5 is a digit

9
Q8) WAP to accept three numbers from the user and display the
largest and the smallest number (using relational operators)
Input-
n1=int(input("enter a number 1:"))
n2=int(input("enter a number 2:"))
n3=int(input("enter a number 3:"))
if(n1>n2 and n1>n3):
print(n1,"n1 is the greatest number")
elif(n2>n1 and n2>n3):
print(n2,"n2 is the greatest number")
else:
print(n3,"n3 is the greatest number")
if(n1<n2 and n1<n3):
print(n1,"n1 is the smallest number")
elif(n2<n1 and n2<n3):
print(n2,"n2 is the smallest number")
else:
print(n3,"n3 is the smallest number")

Output-
enter a number 1:4
10
enter a number 2:5
enter a number 3:9
9 n3 is the greatest number
4 n1 is the smallest number

11
Q9) WAP to accept percentage of a student and display its grade
accordingly based on the table given below:
Percentage Grade

>=90 A

Between 80 and B
89

Input- Between 70 and C


79

Between 60 and D
69

Between 50 and E
59

per=int(input("enter the percentage:"))


if per>=90:
print("Grade A")
elif 89>=per>=80:
print("Grade B")
elif 79>=per>=70:
print("Grade c")
12
elif 69>=per>=60:
print("Grade D")
elif 59>=per>=50:
print("Grade E")
else:
print("Fail")

Output-
enter the percentage:95
Grade A

13
Q10) WAP to find the sum and product of first N natural numbers
Input-
n=int(input("enter a number :"))
sn=(n*(n+1))/2
print(sn,"= sum upto n natural numbers")
i=1
f=1
while i<=n:
f=f*i
i+=1
print("factorial of", n , "is", f)

Output-
enter a number :5
15.0 = sum upto n natural numbers
factorial of 5 is 120

14
Q.11) WAP to find and display the sum of first N even and odd
numbers
Input-
n=int(input("Enter a Number:"))
for i in range (2,2*n+2,2):
print(i)
n=int(input("Enter a Number:"))
for i in range (1,2*n+1,2):
print(i)

Output-
Enter a Number:4
2
4
6
8
Enter a Number:5
1
3
5
7
15
Q.12) WAP to print all the factors of a given number.
Input-
n=int(input("Enter a Number:"))
for i in range (1,n+1):
if n%i==0:
print(i)

Output-
Enter a Number:30
1
2
3
5
6
10
15

16
Q.13) WAP to print all the numbers in the given range divisible by a
given number Num.
Input-
n=int(input("Enter a Number:"))
i=int(input("Enter a Number:"))
for i in range(1,i+1):
if i%n==0:
print(i)

Output-
Enter a Number:2
Enter a Number:10
2
4
6
8
10

17
Q.14) WAP to print the series 1,3,5,7,9….N
Input-
n=int(input("Enter a Number:"))
i=1
while i<=n:
if i%2==1:
print(i)
i+=1

Output-
Enter a Number:10
1
3
5
7
9

18
Q.15) WAP to print the series 1,8,27,64,125……N
Input-
n=int(input("Enter a Number:"))
i=1
while i<=n:
print(i**3)
i+=1

Output-
Enter a Number:6
1
8
27
64
125
216

19
Q.16) WAP to count the number of negative numbers, positive
numbers, odd and even numbers from a list of numbers entered
by the user. The list terminates when the user enters a zero.
Input-
l=[]
x=1
while(x==1):
n=int(input("Enter a number:"))
if n== 0:
break
else:
l.append(n)
print(l)
pos=neg=even=odd=0
for n in l:
if n>=0:
pos+=1
elif n<0:
neg+=1
elif(n%2)==0:
even+=1
20
else:
odd+=1
print("Number of positive numbers : ", pos)
print("Number of negative numbers : ", neg)
print("Number of even numbers : ", even)
print("Number of odd numbers : ", odd)

Output-
Number of positive numbers : 7
Number of negative numbers : 0
Number of even numbers : 0
Number of odd numbers : 0

21
Q.17) WAP to accept a number from the user and check if it is a
palindrome or not.
Input-
n=int(input("Enter number:"))
temp=n
rev=0
while(n>0):
dig=n%10
rev=rev*10+dig
n=n//10
if(temp==rev):
print("The number is a palindrome")
else:
print("The number isn't a palindrome")

Output-
Enter number:50
The number isn't a palindrome
Enter number:55
The number is a palindrome

22
Q.18) WAP to print Fibonacci series up to certain limit.
Input-
n=int(input ("Enter Number of terms to be Printed:"))
n1= 0
n2= 1
count=0
if n<= 0:
print ("Please enter a positive integer, the given number is not
valid")
elif n== 1:
print ("The Fibonacci sequence of the numbers up to",n, ": ")
print(n1)
else:
print ("The fibonacci sequence of the numbers is:")
while count<n:
print(n1)
nth = n1+n2
n1=n2
n2=nth
count+=1
Output-
23
Enter Number of terms to be Printed:3
The fibonacci sequence of the numbers is:
0
1
1
2
3

24
Q19) WAP to display prime numbers up to a certain limit.
Input-
n=int(input("Enter a Number:"))
i=1
p=1
while i<=n:
flag=True
q=2
while (q<p):
if p%q==0:
flag=False
break
q+=1
if flag==True:
print(p)
i+=1
p+=1
Output-4
1
2
3
25
Q20) WAP to accept a number, find and display whether it’s an
Armstrong number or not.
Input-
n=int(input("Enter a number: "))
sum=0
temp=n
while temp>0:
digit=temp%10
sum+=digit**3
temp //= 10
if n==sum:
print(n,"is an Armstrong number")
else:
print(n,"is not an Armstrong number")
Output-
Enter a number: 153
153 is an Armstrong number

26
Q21) WAP to print the sum of the series 1+x1/1!+x2/2!+…….xn/n!
[Exponential series].
Input-
n=int(input("Enter the number of terms :"))
x=int(input("Enter the value of x :"))
sum=1
for i in range(2,n+1):
sum=sum+((x**i)/i)
print("The sum of series is",sum)

Output-
Enter the number of terms :5
Enter the value of x :5
The sum of series is 836.4166666666666

27
Q22)WAP to accept a string and display whether it is a palindrome.
Input-
s=input("Enter a string :")
s=s.upper()
l=len(s)
mid=l//2
rev=-1
for a in range(mid):
if s[a]==s[rev]:
rev-=1
else:
print(s,"is not a palindrome")
break
else:
print(s,"is a palindrome")

Output-
Enter a string :ABA
ABA is a palindrome

28
Q23)WAP to accept a string (a sentence) and returns a string
having first letter of each word in capital letter.
Input-
s=input("Enter a string : ")
l=len(s)
a=0
end=l
s2=''
while a<l :
if a==0 :
s2+=s[0].upper()
a+=1
elif (s[a]==' ' and s[a+1]!=' '):
s2+=s[a]
s2+=s[a+1].upper()
a+=2
else:
s2+=s[a]
a+=1
print("Original string : ",s)
print("Capitalized words string : ",s2)
29
Output-
Enter a string : i am hemanth and i am in class 11
Original string : i am hemanth and i am in class 11
Capitalized words string : I Am Hemanth And I Am In Class 11

30
Q24) Write a program that accepts a string, count, and print the
following-
 No. of Characters
 No. of Spaces
 No. of Letters (Alphabet)
 No. of Digits
 No. of Upper-Case Letters
 No. of Lower-Case Letters
 No. of Special Characters
 No. of Words

Input-
s=input("Enter a string :")
ch=space=letter=digit=upper=lower=special=0
for a in s:
if a.isupper():
upper+=1
if a.islower():
lower+=1
if a.isalpha():

31
letter+=1
elif a.isdigit():
digit+=1
elif a==" ":
space+=1
else:
special+=1
s1=s.strip()
word=1
for i in s1:
if i==" ":
word+=1
print('The number of characters :', len(s))
print('The number of space characters :', space)
print('The number of letters :', letter)
print('The number of digits :', digit)
print('The number of uppercase letters :', upper)
print('The number of lowercase letters :', lower)
print('The number of special characters :', special)
print('The number of words :', word)

32
Output-
Enter a string :Hi there NIcE tO mEet yoU.49242$56#!@
The number of characters : 37
The number of space characters : 5
The number of letters : 20
The number of digits : 7
The number of uppercase letters : 7
The number of lowercase letters : 13
The number of special characters : 5
The number of words : 6

33
Q25) Write a Menu Driven program that executes if the user wants.
(Use functions from math and random Module)
Menu.
1. Find Absolute Value of a number
2. Find Square root of a number
3. Find Logarithmic value of number
4. Generate 4-digit random integer
5. Exit
Input-
import math
import random
print("1 - Find Absolute Value of a number")
print("2 - Find Square root of a number")
print("3 - Find Logarithmic value of number")
print("4 - Generate 4-digit random integer")
print("5 - Exit")
n=int(input("Select an option from the above menu : "))
if n>=1 and n <= 3:
num=int(input("Enter a number : "))
if n==1:
print("Absolute value of",num,"is : ",abs(num))
34
elif n==2:
print("Square root of",num,"is : ",math.sqrt(num))
else:
print("Logarith value of",num,"is : ",math.log10(num))
if n==4:
print("Random four digit
number :",random.randint(1000,9999))
elif n==5:
print("Exiting...")
else:
print("Please choose a valid option!")

Output-
1 - Find Absolute Value of a number
2 - Find Square root of a number
3 - Find Logarithmic value of number
4 - Generate 4-digit random integer
5 - Exit
Select an option from the above menu : 3
Enter a number : 5
Logarith value of 5 is : 0.6989700043360189
35
Q26) Write a Menu Driven program to perform the following
operations on a list. The program should execute as long as the user
wants. Menu.
1. Create a List
2. Append a random 4 digit integer into the list
3. Extend the list
4. Insert an element into a list at a particular position
5. Remove an element from the list based on the user's choice. a. The
last element b. The element at a particular position c. The first
occurrence of the element
6. Print the largest element and smallest element in the list
7. Find the second largest and second smallest element in the list.
8. Sort the list in ascending or descending order as per user's choice
(Do not change original list)
9. Reverse the elements of a list (Do not change original list)
10. Clear the list
11. Exit
Input-
import random
while True:
a=list(eval(input("Enter a List:")))
36
c=input("Do you wish to continue yes/no:")
if c=="yes":
continue
elif c=="no":
break
b=list(eval(input("Enter a List to extend:")))
n=int(input("Enter a Number:"))
p=int(input("Enter at what index you want to insert:"))
q=int(input("Enter what index you want to remove:")) 29
r=int(input("Enter a the element value you want to remove:"))
x=int(input("Enter 1 to sort in ascending or 2 to sort in
descending:"))

a.append(random.randrange(-100000,100000,1))
a.append(random.randrange(-100000,100000,1))
a.append(random.randrange(-100000,100000,1))
a.append(random.randrange(-100000,100000,1))
a.extend(b)
a.insert(p,n)
a.pop()
a.pop(q)
37
a.remove(r)
print("Largest No. in list a =",max(a),"smallest No. in list a
=",min(a))
print(a)
a.remove(max(a))
a.remove(min(a))

print("2nd Largest No. in list a =",max(a),"2nd smallest No. in list a


=",min(a))
z=list(a)
if x==1:
print(z.sort())
elif x==2:
print(z.sort(reverse=True))
else:
print("to no sort")
print(z)
y=list(a)
y.reverse()
print(y)
print(a)
38
Output-
Enter a List:1,224,12344,2452,13,123

Do you wish to continue yes/no:yes


Enter a List:1,2,84,1,499,4189126,4891,1189,1891,11,18,1
Do you wish to continue yes/no:no
Enter a List to extend:1,18,1818,19,9191,9191,9191,19
Enter a Number:25
Enter at what index you want to insert:5
Enter what index you want to remove:8
Enter a the element value you want to remove:1
Enter 1 to sort in ascending or 2 to sort in descending:2
Largest No. in list a = 4189126 smallest No. in list a = 1
[2, 84, 1, 499, 25, 4189126, 4891, 1891, 11, 18, 1, 99896, 49325, 92385,
3301, 1, 18, 1818, 19, 9191, 9191, 9191]
2nd Largest No. in list a = 99896 2nd smallest No. in list a = 1
None
[99896, 92385, 49325, 9191, 9191, 9191, 4891, 3301, 1891, 1818, 499,
84, 25, 19, 18, 18, 11, 2, 1, 1]
[9191, 9191, 9191, 19, 1818, 18, 1, 3301, 92385, 49325, 99896, 1, 18, 11,
1891, 4891, 25, 499, 84, 2]
39
[2, 84, 499, 25, 4891, 1891, 11, 18, 1, 99896, 49325, 92385, 3301, 1, 18,
1818, 19, 9191, 9191, 9191]
Q27) Write a program to accept values into a list and search for a
particular element from a list of numbers (Linear Search)
Input-
a=list(eval(input("Enter a List:")))
b=int(input("Enter a number to find:"))
for i in a:
if i==b:
print("Found",i)
else:
print("Not Found")
Output-
Enter a List:1,12,1,2,4,98
Enter a number to find:12
Not Found
Found 12
Not Found
Not Found
Not Found
Not Found
40
Q28) Write a program to accept a list of numbers, find and print the
sum and the average.
Input-
a=list(eval(input("Enter a List:")))
su=0
for i in a:
su+=i
print(su)
print(su/len(a))

Output-
Enter a List:1,2,3,4,5
15
3.0

41
Q29) Write a program to input two lists and create a third list that
contains the elements from both the lists and sort it
Input-
a=list(eval(input("Enter a List:")))
b=list(eval(input("Enter a List:")))
c=list(a)+list(b)
print(c)
c.sort()
print(c)

Output-
Enter a List:1,2,2,3,5,8
Enter a List:3,4,966,54,2,5
[1, 2, 2, 3, 5, 8, 3, 4, 966, 54, 2, 5]
[1, 2, 2, 2, 3, 3, 4, 5, 5, 8, 54, 966]

42
Q30) Write a program to accept a list of numbers from the user
(between 1-15) and replace all the entries in the list which are greater
than 10 by 100
Input-
a=list(eval(input("Enter a List of Numbers between 1 to 15:")))
for i in range(len(a)):
if a[i]>10:
a[i]=100
print(a)

Output-
Enter a List of Numbers between 1 to 15 : 1,15,2,4,6,7,11,12,13
[1, 100, 2, 4, 6, 7, 100, 100, 100]

43
Q31) Write a program to accept a string from the user and convert it
to a list
Input-
a=input("Enter a string:")
b=list(a)
print(b)
Output-
HEMANTH
['H', 'E', 'M', 'A', 'N', 'T', 'H']

44
Q32) Write a program to accept two lists of same size and form
another list which has the sum of the corresponding elements of both
the lists
Input-
a=list(eval(input("Enter 1st List:")))
b=list(eval(input("Enter 2nd List")))
c=b.copy()
if len(a)==len(b):
for i in range(len(a)):
c[i]+=a[i]
else:
print('error')
print(c)

Output-
Enter 1st List:[23,76,49]
Enter 2nd List[21,34,45]
[44, 110, 94]

45
Q33) Write a program that rotates the elements of a list so that the
elements at the first index moves to the second index, the second to
third and last to first.
Input-
a=list(eval(input("Enter a List:")))
a=a[-1:]+a[ :-1]
print(a)

Output-
Enter a List:1,2,3,4,5,6,7,8,9
[9, 1, 2, 3, 4, 5, 6, 7, 8]

46
Q34) Write a program to accept a list of numbers and then put even
elements into one list and odd elements into another.
Input-
a=list(eval(input("Enter list of number:")))
b=[]
c=[]
for i in a:
if i%2==0:
b.append(i)
elif i%2==1:
c.append(i)
print(b, ”are list of even elements ”)
print(c, ”are list of odd elements ”)

Output-
Enter list of number:1,28,48,52,4,25,7,9,3,44
[28, 48, 52, 4, 44] are list of even elements
[1, 25, 7, 9, 3] are list of odd elements

47
Q35) Write a program to read a list of words. Find and print the
longest word in the list with its length.
Input-
l=list(eval(input("enter a List of Words:")))
big=l[0]
pos=0
for i in range(1,len(l)):
if len(l[i])>len(big):
big=l[i]
pos=i
print("largest is =",big,"its position is=",pos+1)

Output-
enter a List of Words:'hemanth','surya','kamran'
largest is = hemanth its position is= 1

48
Q36) Write a program to convert a list to tuple and replicate it 3 times
Input-
a=list(eval(input("Enter tuple of number:")))
b=tuple(a)
print((b,)*3)

Output-
Enter tuple of number:1,2,3,4,5
((1, 2, 3, 4, 5), (1, 2, 3, 4, 5), (1, 2, 3, 4, 5))

49
Q37) Write a program in python to remove an item from a tuple
Input-
a=tuple(eval(input("Enter tuple of number:")))
c=int(input("enter a the index to remove:"))
b=list(a)
b.pop(c)
d=tuple(b)
print(d)

Output-
Enter tuple of number:1,2,3,4,5
enter a the index to remove:2
(1, 2, 4, 5)

50
Q38) Write a program to find the index of each element of a tuple
Input-
a=tuple(eval(input("Enter tuple of number:")))
for i in range(len(a)):
print(i)

Output-
Enter tuple of number:1,2,3,4,5
0
1
2
3
4

51
Q39) Write a program to accept the details (Id, Name, Age, DOB,
Salary) of Five employees into a tuple Employee. Unpack the details of
first employee into variables Id, Name, Age, DOB and Salary
Input-
for i in range(5):
a=tuple(eval(input("Enter Details Of Employee:")))
Id,Name,Age,Dob,Salary=a
print("Employee
I'd=",Id ,"Name=",Name ,"Age=",Age ,"D.O.B=",Dob ,"Salary=",Sa
lary )

Output-
Enter Details Of Employee:1,hemanth,17,2005,5000
Employee I'd= 1 Name= hemanth Age= 17 D.O.B= 2005 Salary= 5000
Enter Details Of Employee:9145,'sur',16,2006,4750
Employee I'd= 9145 Name= sur Age= 16 D.O.B= 2006 Salary= 4750
Enter Details Of Employee:6789,'kam',18,2004,4900
Employee I'd= 6789 Name= kam Age= 18 D.O.B= 2004 Salary= 4900
Enter Details Of Employee:4003,'suraj',22,1999,8000 45
Employee I'd= 4003 Name= suraj Age= 22 D.O.B= 1999 Salary= 8000
52
Enter Details Of Employee:10002, 'div',19,1003,4250
Employee I'd= 10002 Name= div Age= 19 D.O.B= 2003 Salary= 4250
Q40) Write a program to reverse a tuple
Input-
a=tuple(eval(input("Enter a Tuple:")))
b=list(a)
b.reverse()
c=tuple(b)
print(c)

Output-
Enter a Tuple:1,2,3,4,5
(5, 4, 3, 2, 1)

53
Q41) Write a program to accept five strings into a tuple and find the
length of the shortest string.
Input-
l=tuple(eval(input("enter a tuple of Words:")))
small=l[0]
pos=0
if len(l)==5:
for i in range(1,len(l)):
if len(l[i])<len(small):
small=l[i]
pos=i
print("shortest is =",small,"its position is=",pos+1)
else:
print("ERROR")

Output-
enter a tuple of words
Words:'jayakanth','surya','kamran','hemanth','karthik'
shortest is = surya its position is= 2
54
Q42) Accept marks of five students in three subjects into a tuple. For
each find the and display the following a. Maximum marks out of
three subjects b. Minimum marks out of three subjects c. Sum and
average of the marks in three subjects.
Input-
su=0
for i in range(1,6):
a=tuple(eval(input("Enter Details Of Students:")))
print("maximum marks of 3 sub=",max(a),"minimum marks of 3
sub=",min(a))
for i in a:
su+=i
print("sum of marks=",su,"Average=",su/3)
su=su-su

Output-
Enter Details Of Students:97,98,100
maximum marks of 3 sub= 100 minimum marks of 3 sub= 97
sum of marks= 295 Average= 98.33333333333333
55
Enter Details Of Students:45,70,65 49
maximum marks of 3 sub= 70 minimum marks of 3 sub= 45
sum of marks= 180 Average= 60.0
Enter Details Of Students:21,54,65
maximum marks of 3 sub= 65 minimum marks of 3 sub= 21
sum of marks= 140 Average= 46.666666666666664
Enter Details Of Students:54,78,98
maximum marks of 3 sub= 98 minimum marks of 3 sub= 54
sum of marks= 230 Average= 76.66666666666667
Enter Details Of Students:99,100,98
maximum marks of 3 sub= 100 minimum marks of 3 sub= 98
sum of marks= 297 Average= 99.0

56
Q43) Write a program to accept a sentence/ paragraph from the user.
Create a dictionary that stores each word and its Count of its
frequency in the given sentence /paragraph as key-value pairs
respectively.
Input-
a=input("Enter a sentence:")
b=a.split(" ")
print(b)
d={}
for i in b:
d[i]=b.count(i)
print(d)
Output-
Enter a sentence:hemanth is pro
[‘hemanth', 'is', 'pro']
{'hemanth': 1, 'is': 1, 'pro': 1}

57
Q44) Repeatedly ask the user to enter a team name and how many
games the team has won and how many they have lost. Store this
information in a dictionary where the keys are the team names and
the values are the list of the form [wins, losses] a. Using the dictionary,
created above, allow the user to enter a team name and print out the
team's winning percentage b. Using the dictionary ,create a list whose
entries are the number of wins of each team c. Using the
dictionary ,create a list of all those teams that have only winning
record (i.e. zero losses)
Input-
n=int(input("how many team names u want to enter:"))
d={}
c=[]
f=[]
for i in range(n):
x=[]
a=input("team name:")
p=int(input("Enter wins:"))
q=int(input("Enter losses:"))
x.append(p)
c.append(p)
58
x.append(q)
d[a]=x
print(d)
b=input("team name:")
i=d[b]
print((i[0]/sum(i))*100)
print(c)
for x in d.keys():
if d[x][1]==0:
f.append(x)
print(f)
else:
print("none")

Output-
how many team names u want to enter:1

team name:hemanth

Enter wins:5

59
Enter losses:0
{"'hemanth'": [5, 0]}

team name:'hemanth'
100.0
[5]
["'hemanth'"]

60
Q45) Write a program to repeatedly ask the user to enter product
names and prices. Store all of these in a dictionary whose keys are the
product names and whose values are the prices. ****when the user is
done entering products and prices, allow them to repeatedly enter a
product name and print the corresponding price or print a message
product does not exist.
Input-
n=int(input("how many product names u want to enter:"))
d={}
for i in range(n):
a=input("product name:")
b=int(input("product price:"))
d[a]=b
print(d)
x=input("product name:")
if x in d:
print(d[x])
else:
print("none")
Output-
how many product names u want to enter:2
61
product name:'x'
product price:100
product name:'y'
product price:150
{"'x'": 100, "'y'": 150}
product name:'x'
100

62
Q46)Given the dictionary
X={'11A':"Uzma",'11B':"Sonia",'11C':"Doyel",'11D':"Sreeja"}
Create a dictionary with the opposite mapping, i.e. write a program to
create the dictionary as: Inverted_X=
{"Uzma":'11A',"Sonia":'11B',"Doyel":'11C',"Sreeja":'11D'}
Input-
X={'11A':"Uzma",'11B':"Sonia",'11C':"Doyel",'11D':"Sreeja"}
X_inverted={}
for i in X.keys():
X_inverted[X[i]]=i
print(X_inverted)

Output-
{'Uzma': '11A', 'Sonia': '11B', 'Doyel': '11C', 'Sreeja': '11D'}

63
Q47) Given two dictionaries say D1 and D2.Write a program that lists
the overlapping keys of the two dictionaries i.e. if a key of D1 is also
present in D2, then list it.
Input-
d1 = {"a":1,"b":2,"c":8,"l":0,"p":4,"i":8,"g":6}
d2 = {"x":2,"y":2,"z":4,"p":7,"c":1,"i":3}
a=[]
for i in d1.keys():
if i in d2.keys():
a.append(i)
print(a)

Output-
['c', 'p', 'i']

64
Q48) Create a dictionary whose keys are the names of the month and
whose values are the number of days in the month a. Printout all of
the keys in alphabetical order b. Print out the key –value pair sorted
by the no of days in a month c. Print out all the months with 31 days
Input-
m={"jan":31,"feb":28,"march":31,"april":30,"may":31,"june":30,"
july":31,"aug":31,"sept":30,"oct":31,"nov":30,"dec":31}
a=[]
b=[]
n={}
z={}
for i in m:
a.append(i)
a.sort()
print(a)
for y in m:
if m[y]==31:
print(y,"sorted")
for i in m:
n[m[i]]=i
print(n)
65
c=[]
a=n.items()
b=list(a)
print(b)
b.sort()
x=dict(b)
print(x)
for j in x:
z[x[j]]=j
print(z)

Output-
['april', 'aug', 'dec', 'feb', 'jan', 'july', 'june', 'march', 'may', 'nov',
'oct', 'sept']
jan sorted
march sorted
may sorted
july sorted
aug sorted
oct sorted
dec sorted
66
{31: 'dec', 28: 'feb', 30: 'nov'}
[(31, 'dec'), (28, 'feb'), (30, 'nov')]
{28: 'feb', 30: 'nov', 31: 'dec'}
{'feb': 28, 'nov': 30, 'dec': 31}

67

You might also like