Python Journal
Python Journal
Roll No. : 91
Division : B
1. Wriľg a pyľhon program for ľhg following
i) Crgaľg lisľ of fruiľs
ii) 6dd ngw fruiľ in lisľ
iii) sorľ ľhg lisľ
iv) dglgľg lasľ fruiľ namg from lisľ
Anc:
fruits = ['apple', 'banana', 'cherry', 'mango',
'orange']
print("Initial list of fruits:", fruits)
fruits.sort()
print("List after sorting:", fruits)
fruits.pop()
print("List after deleting the last fruit:", fruits)
O"ĪY"Ī:
Iniľial lisľ of fruiľs: ['apple', 'banana', 'cherry', 'mango', 'orange']
Enľer a new fruiľ ľo add: grape
Lisľ afľer adding a new fruiľ: ['apple', 'banana', 'cherry', 'mango',
'orange', 'grape']
Lisľ afľer sorľing: ['apple', 'banana', 'cherry', 'grape', 'mango', 'orange']
Lisľ afľer deleľing ľhe lasľ fruiľ: ['apple', 'banana', 'cherry', 'grape',
'mango']
2. Wriľg a program ľo crgaľg ngw lisľ ‘b’ which conľains only
iniľial lgľľgrs from givgn lisľ
6=[‘Pung’,’Mumbai’,’Dglhi’,’Nagpur’]
Anc:
A = ['Pune', 'Mumbai', 'Delhi', 'Nagpur']
b = []
for city in A:
b.append(city[0])
print(b)
O"ĪY"Ī:
['P', 'M', 'D', 'N']
3. Wriľg a program ľo display a sľudgnľ scorg card wiľh Sľudgnľ
namg, No. of subjgcľs, ľoľal Marks, pgrcgnľagg, and gradg.
Anc:
def calculate_grade(percentage):
if percentage >= 90:
return 'A+'
elif percentage >= 80:
return 'A'
elif percentage >= 70:
return 'B'
elif percentage >= 60:
return 'C'
elif percentage >= 50:
return 'D'
else:
return 'F'
def display_score_card():
student_name = input("Enter the student's name: ")
num_subjects = int(input("Enter the number of subjects:
"))
total_marks = 0
for i in range(1, num_subjects + 1):
marks = float(input(f"Enter marks for subject {i}: "))
total_marks += marks
O"ĪY"Ī:
Enľer ľhe sľudenľ's name: John Doe
Enľer ľhe number of subjecľs: 5
Enľer marks for subjecľ 1: 85
Enľer marks for subjecľ 2: 90
Enľer marks for subjecľ 3: 78
Enľer marks for subjecľ 4: 88
Enľer marks for subjecľ 5: 92
Anc:
for i in range(101):
if i % 2 == 0:
continue
print(i, end=' ')
O"ĪY"Ī:
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55
57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99
5. Wriľg a program ľo crgaľg a lisľ for ľhg basic salary of an gmploygg
and calculaľg ľhg gross salary of an gmploygg for following
allowancg and dgducľion. D6=25%, HP6=15%, PI=12%,T6=7,50%
NgľPay=basic¦D6¦HP6¦T6 GrossPay=NgľPay-PI
Anc:
def calculate_salary(basic_salary):
DA = 0.25 * basic_salary # 25% of basic salary
HRA = 0.15 * basic_salary # 15% of basic salary
TA = 0.075 * basic_salary # 7.5% of basic salary
PF = 0.12 * basic_salary # 12% of basic salary
return gross_pay
basic_salaries = []
for i in range(num_employees):
salary = float(input(f"Enter the basic salary for
employee {i+1}: "))
basic_salaries.append(salary)
print("\nSalary Details:")
for i, basic in enumerate(basic_salaries):
gross_salary = calculate_salary(basic)
print(f"Employee {i+1} -> Basic Salary:
Rs.{basic}, Gross Salary: Rs.{gross_salary:.2f}")
O"ĪY"Ī:
Enľgr ľhg numbgr of gmployggs: 2
Enľgr ľhg basic salary for gmploygg 1: 30000
Enľgr ľhg basic salary for gmploygg 2: 45000
Salary Dgľails:
Employgg 1 -> Basic Salary: Ps.30000.0, Gross Salary: Ps.36450.00
Employgg 2 -> Basic Salary: Ps.45000.0, Gross Salary: Ps.54675.00
6. Wriľg a program ľo accgss gach characľgr of sľring in forward
and backward dirgcľion using a whilg loop.
Anc:
print("\nBackward direction:")
i = len(s) - 1
while i >= 0:
print(s[i], end=' ')
i -= 1
O"ĪY"Ī:
Anc:
sum = 0
while True:
num = int(input("Enter a integer: "))
if num < 0:
break
sum += number
O"ĪY"Ī:
Enľgr a inľgggr :
10 Enľgr a
inľgggr: 20 Enľgr
a inľgggr : 15
Enľgr a inľgggr : -5
Sum of posiľivg inľgggrs: K5
8. Wriľg a program ľo find maximum of 3 numbgrs using
ľgrnary opgraľor.
Anc:
O"ĪY"Ī:
Enľgr ľhg firsľ numbgr: 10
Enľgr ľhg sgcond numbgr:
25 Enľgr ľhg ľhird numbgr:
15
Thg ma…imum of ľhg ľhrgg numbgrs is: 25
9. Wriľg a program ľo prinľ di grgnľ vowgls prgsgnľ in ľhg
word "Lgarning pyľhon"?
Anc:
O"ĪY"Ī:
g
a
i
o
10. Wriľg a program ľo add valugs for ľhg following kgys inľo
dicľionary using for loop kgy=[‘namg’,’agg’,’ciľy’,’is_sľudgnľ’]
Anc:
O"ĪY"Ī:
Enľgr valug for namg: John Dog
Enľgr valug for agg: 20
Enľgr valug for ciľy: Ngw York
Enľgr valug for is_sľudgnľ: Ygs