0% found this document useful (0 votes)
3 views6 pages

Python 1

python

Uploaded by

Chandradasa
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)
3 views6 pages

Python 1

python

Uploaded by

Chandradasa
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/ 6

 1 සිට 10 දක්වො ඇති ඔත්පත් සංඛයො පගොනුවකට ලිවීමට අදොල python

x=open('2.txt','w')
for i in range(1,10,2):
b=str(i)
x.write(b+'\n')
x.close()

 විෂයන්න තුනක ලකුණු ඇතුලත් කර ඒවොපේ එකතුව සහ සොමොනයය පසවීම පසොයො පගොනුවක
ෙන්න .

total=0
x=open('4.txt','w')
x.write('Subject\t\t\t'+'Marks\n')
x.write('------------------------------\n')
for i in range(3):
name=str(input('Enter Subject:'))
marks=str(input('Enter Marks:'))
x.write(name+'\t\t\t'+marks+'\n')
total=total+int(marks)
average=round(total/3,2)
t=str(total)
a=str(average)
x.write('------------------------------\n')
x.write('Total Marks is: \t'+t+'\n')
x.write('Average Marks is: \t'+a+'\n')
x.close()

 .
for count in range(2):
subject=['ICT','BS','AC']
total=0
x=open('5.txt','a')
name=str(input('Enter your name:'))
x.write('--------------------------------------------\n')
x.write('Your name :'+name+'\n')
x.write('--------------------------------------------\n')
x.write('Subject\t\t\t'+'Marks\t\tGrade\n')
x.write('--------------------------------------------\n')
for i in range(3):
s=subject[i]
marks=str(input('Enter '+s+' Marks:'))
m=int(marks)
if m>=75:
g='A'
elif m>=65:
g='B'
elif m>=55:
g='C'
elif m>=35:
g='S'
else:
g='W'
x.write(s+'\t\t\t'+marks+'\t\t'+g+'\n')
total=total+int(marks)
average=round(total/3,2)
t=str(total)
a=str(average)
x.write('--------------------------------------------\n')
x.write('Total Marks is: \t'+t+'\n')
x.write('Average Marks is: \t'+a+'\n')
x.write('--------------------------------------------\n')
x.close()

jrK f;aÍu (Selection sort)


#function
def selection_sort(L):
for i in range(len(L)-1):
min_index = i
for j in range(i+1, len(L)-1):
if L[j] < L[min_index]:
min_index = j
L[i], L[min_index] = L[min_index], L[i]
#program
L = [3, 1, 41, 59, 26, 53, 59]
print(L)
selection_sort(L)
print(L)

බුබුළු මත්රීම (Bubble sort)


#function
def bubble_sort(our_list):
for i in range(len(our_list)):
for j in range(len(our_list) - 1):
if our_list[j] > our_list[j+1]:
our_list[j], our_list[j+1] = our_list[j+1], our_list[j]
#program
our_list = [19, 13, 6, 2, 18, 8]
bubble_sort(our_list)
print(our_list)

You might also like