0% found this document useful (0 votes)
13 views14 pages

Python Journal

Uploaded by

swarajladke20
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)
13 views14 pages

Python Journal

Uploaded by

swarajladke20
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/ 14

Student Name : Swaraj Ambadas Ladke

Subject : Python Part A: Preliminary


Term 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)

new_fruit = input("Enter a new fruit to add: ")


fruits.append(new_fruit)
print("List after adding a new fruit:", 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

percentage = (total_marks / (num_subjects * 100)) * 100


grade = calculate_grade(percentage)

print("\n--- Student Score Card ---")


print(f"Student Name: {student_name}")
print(f"Number of Subjects: {num_subjects}")
print(f"Total Marks: {total_marks}/{num_subjects * 100}")
print(f"Percentage: {percentage:.2f}%")
print(f"Grade: {grade}")
display_score_card()

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

--- Sľudenľ Score Card ---


Sľudenľ Name: John Doe
Number of Subjecľs: 5
Toľal Marks: 433/500
Percenľage: 86.60%
Grade: A
4. Wriľg a program ľo prinľ odd numbgrs bgľwggn 0 ľo 100
using conľinug sľaľgmgnľ.

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

net_pay = basic_salary + DA + HRA + TA


gross_pay = net_pay - PF

return gross_pay

basic_salaries = []

num_employees = int(input("Enter the number of


employees: "))

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:

s = input("Enter a string: ")


print("Forward direction:")
i = 0
while i < len(s):
print(s[i], end=' ')
i += 1

print("\nBackward direction:")
i = len(s) - 1
while i >= 0:
print(s[i], end=' ')
i -= 1

O"ĪY"Ī:

Enľgr a sľring: Pyľhon


Iorward dirgcľion:
Pyľhon
Backward
dirgcľion: n o h ľ y
P
7. Wriľg a program ľo prinľ sum of posiľivg inľgggrs whgn usgr
gnľgr nggaľivg valug brgak ľhg loop (whilg)

Anc:

sum = 0

while True:
num = int(input("Enter a integer: "))

if num < 0:
break

sum += number

print(f"Sum of positive integers: {sum}")

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:

a = int(input("Enter the first number: "))


b = int(input("Enter the second number: "))
c = int(input("Enter the third number: "))

max = a if a > b and a > c else b if b > c else c

print("The maximum of the three numbers is:", max)

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:

word = "Learning python"


vowels = "aeiouAEIOU"
found_vowels = ""

for char in word:


if char in vowels and char not in found_vowels:
found_vowels += char
print(char)

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:

keys = ['name', 'age', 'city', 'is_student']


student_info = {}

for key in keys:


value = input(f"Enter value for {key}: ")
student_info[key] = value

print("\nStudent Information Dictionary:")


print(student_info)

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

Sľudgnľ Informaľion Dicľionary:


{'namg': 'John Dog', 'agg': '20', 'ciľy': 'Ngw York', 'is_sľudgnľ': 'Ygs'}

You might also like