Python
Python
School
PYTHON
PROGRAMMING
Submitted to…
Ghazanfer Ali Submitted by ….
Name:- Yashika Jaiswal
Class:- XI Sec:- Sci
Roll No. :- 14
1
INDEX
Serial PROGRAM PAGE
NO. NO. NO.
01. Program 1
02. Program 2
03. Program 3
04. Program 4
05. Program 5
06. Program 6
07. Program 7
08. Program 8
09. Program 9
10. Program 10
11. Program 11
12. Program 12
13. Program 13
14. Program 14
15. Program 15
16. Program 16
17. Program 17
18. Program 18
19. Program 19
20. Program 20
21. Program 21
22. Program 22
23. Program 23
24. Program 24
25. Program 25
2
# Program to print elements of a list [‘q’,’w’,’e’,’r’,’t’,’y’] in separate lines along with
element’s both indexes(positive and negative).
L=['q','w','e','r','t','t','y']
>>> length=len(L)
print("At indexes",a,"and",(a-length),"element:",L[a])
OUTPUT:
3
# Program to count frequency of a given element in a list of numbers.
lst=eval(input("Enter list:"))
length=len(lst)
count = 0
if element == lst[i]:
count+=1
if count == 0:
else:
OUTPUT:
Enter list:[1,1,1,2,2,3,4,2,2,5,2,2,5]
Enter element :2
4
2 has frequency as 6 in given list
5
# Program to find frequencies of all element of a list. Also, print the list of unique
elements in the list and duplicate the given list .
lst=eval(input("Enter list:"))
length=len(lst)
uniq=[]
dupl=[]
count=i=0
element = lst[i]
count =1
i+=1
if element == lst[j]:
count += 1
else:
dupl.append(element)
else:
i+=1
print("Original list",lst)
OUTPUT:
Enter list:[2,3,4,5,3,6,7,3,5,2,7,1,9,2]
6
Original list [2, 3, 4, 5, 3, 6, 7, 3, 5, 2, 7, 1, 9, 2]
7
# Program to create a phone dictionary for all your friends and then print it .
PhoneDict = {"Madhav":1234567,"Steven":7654321,"Dilpreet"
:6734521,"Rabiya":4563217,"Murughan":3241567,"Sampree":4673215}
print( name,":",PhoneDict[name])
OUTPUT:
Madhav : 1234567
Steven : 7654321
Dilpreet : 6734521
Rabiya : 4563217
Murughan : 3241567
Sampree : 4673215
8
# Program to create a dictionary containing names of competition winner students as keys
and numbers of their wins as values.
CompWinners = {}
for a in range(n) :
CompWinners[key] = value
print(CompWinners)
OUTPUT:
9
# Program to count the frequency of a list – elements using a dictionary.
import json
sentence = "This is a super idea This \ idea will change the idea will change the idea of
learning"
words = sentence.split()
d={}
key = one
if key not in d:
count = words.count(key)
d[key] = count
print(json.dumps(d,indent=1))
OUTPUT:
['This', 'is', 'a', 'super', 'idea', 'This', '\\', 'idea', 'will', 'change', 'the', 'idea', 'will', 'change',
'the', 'idea', 'of', 'learning']
"This": 2,
"is": 1,
"a": 1,
"super": 1,
"idea": 4,
"\\": 1,
10
"will": 2,
"change": 2,
"the": 2,
"of": 1,
"learning": 1
11
# Program to calculate and roots of a quadratic equation : ax2+bx + c = 0 (a = 0)
import math
if a == 0:
else:
delta = b*b-4*a*c
if delta > 0 :
print("Root1=",root1,"Root2=",root2)
elif delta==0:
root1=-b/(2*a);
print ("Roots1=",root1,"Roots2=",root1)
else:
OUTPUT :
Enter a :3
Enter b :5
12
Enter c :2
>>>
= RESTART :
Enter a :2
Enter b :3
Enter c :4
>>>
= RESTART:
Enter a :2
Enter b :4
Enter c :2
>>>
13
# Program that reads a line and prints its statistics like :
lowercount = uppercount = 0
digitcount = alphacount = 0
for a in line :
if a.islower() :
lowercount += 1
elif a.isupper() :
uppercount += 1
elif a.isdigit() :
digitcount += 1
if a.isalpha() :
alphacount += 1
OUTPUT :
Number of alphabet : 18
Number of digits : 3
14
# Program to find frequencies of all elements of a list . Also , print the list of unique
elements in the list and duplicate elements in the given list .
length = len(lst)
uniq = []
dupl = []
count = i = 0
element = lst[i]
count = 1
i += 1
if element == lst[j]:
count+=1
else:
if count == 1 :
uniq.append(element)
else :
dupl.appent(elements)
else:
i += 1
OUTPUT:
15
Enter list :[2,3,4,5,3,6,7,3,5,2,7,1,9,2]
Element 2 frequency : 3
Element 3 frequency : 3
Element 4 frequency : 1
Element 5 frequency : 2
Element 6 frequency : 1
Element 7 frequency : 2
Element 1 frequency : 1
Element 9 frequency : 1
16
# Program to find multiples of number( the divisor ) out of given 5 numbers .
count = 0
if remainder == 0 :
count += 1
if remainder == 0 :
count += 1
if remainder == 0 :
count += 1
if remainder == 0 :
count += 1
17
if remainder == 0 :
count += 1
print()
OUTPUT :
3450.0
>>>
18
# Program that input three numbers and calculate two sums as per this :
# Sum2 as the sum of non - duplicate numbers ; if there are duplicate numbers in input ,
ignores them .
sum1 = sum2 = 0
if num1 == num2 :
if num3 != num1 :
sum2 += num3
else :
if num1 == num3 :
sum2 += num2
else :
if num2 == num3:
sum2 += num1
else :
OUTPUT :
Enter number 1 :2
Enter number 2 :3
Enter number 3 :4
19
Numbers are 2 3 4
>>>
== RESTART:
Enter number 1 :3
Enter number 2 :2
Enter number 3 :3
Numbers are 3 2 3
>>>
== RESTART:
Enter number 1 :4
Enter number 2 :4
Enter number 3 :4
Numbers are 4 4 4
>>>
20
# Program to display a menu for calculating area of a circle or perimeter of a circle .
if choice == 1 :
area = 3.14159*radius*radius
else :
perm = 2*3.14159*radius
OUTPUT :
1. Calculate Area
2. Calculate Perimeter
>>>
== RESET
1. Calculate Area
2. Calculate Perimeter
>>>
21
22