Tamil
Nadu Public Service Commission (TNPSC) has released a notification
for the recruitment of 9,351 Junior Assistants, Typists,
Steno-Typists and more. Interested candidates may check the
vacancy details and apply online from 14-11-2017 to 13-12-2017.
More details about TNPSC Recruitment (2018), including number of vacancies, eligibility criteria, selection procedure, how to apply and important dates, are given below: |
|||||||||
| Vacancy
Details: •Post Name: Junior Assistant •No. of Vacancies: 4,301 •Pay Scale: Rs. 5,200-20,200 •Grade Pay: Rs. 2,400 •Post Name: Typist •No. of Vacancies: 3,463 •Pay Scale: Rs. 5,200-20,200 •Grade Pay: Rs. 2,400 •Post Name: Steno-Typist •No. of Vacancies: 815 •Pay Scale: Rs. 5,200-20,200 •Grade Pay: Rs. 2,800 |
|||||||||
Job
Location: Tamil
Nadu
|
|||||||||
Eligibility
Criteria for TNPSC Junior Assistants, Steno-Typists and more:
|
|||||||||
Educational
Qualification:
For Junior Assistants: Candidates should have passed 10+2 or Graduation Degree in any stream from a recognised university.For Typists/Steno-Typists: Candidates should have passed 10+2 or Graduation Degree in any stream from a recognised university and cleared Government Technical Examination both in typewriting and in shorthand in concerned language. |
|||||||||
Age
Limit (as on 01-07-2017): Minimum
18 years and Maximum 30 years
|
|||||||||
Age
Relaxation:
|
|||||||||
Selection
Process: Selection
of candidates will be made on the basis of Written Examination.
|
|||||||||
Application
Fee: It
is mandatory for all candidates to pay Rs. 150 to register in
One-Time Registration. General/UR/OBC candidates have to pay Rs.
100 as Examination Fee through SBI Bank Challan OR online mode
using Net-banking/Credit or Debit Card. SC/ST/PWD don’t have to
pay Examination Fee.
|
|||||||||
How
to Apply: Interested
and eligible candidates may apply online through TNPSC website -
http://www.tnpscexams.net/ - from 14-11-2017 to 13-12-2017.
|
|||||||||
| Important
Dates: • Starting Date of Online Application: 14-11-2017 • Last Date of Online Application: 13-12-2017 • Last Date for Payment through Bank Challan: 15-12-2017 • Date of Examination: 11-02-2018 Other Jobs:Junior Clerk-cum-Typist - 150 PostsOffice Assistants recruitment recruitment of 849 Special Reserve Police Constables. Recruitment of 1,058 First Division Assistant and Second Division Assistant Bank of Baroda (BOB) - 427 Specialist Officers recruitment Public Service Commission (TNPSC) |
Thursday, November 30, 2017
Public Service Commission (TNPSC)
Bank of Baroda (BOB) - 427 Specialist Officers recruitment
Bank
of Baroda (BOB) has released a notification for the recruitment of
427 Specialist Officers in various departments. Interested
candidates may check the vacancy details and apply online from
14-11-2017 to 08-12-2017.
More details about Bank of Baroda Recruitment (2018), including number of vacancies, eligibility criteria, selection procedure, how to apply and important dates, are given below: |
Vacancy Details: •Post Name: Specialist Officer •No. of Vacancies: 427 |
Pay Scale: •Grade/Scale Name: JMG/S-I •No. of Vacancies: 150 •Pay Scale: Rs. 23,700-42,020 •Grade/Scale Name: MMG/S-II •No. of Vacancies: 127 •Pay Scale: Rs. 31,705-45,950 •Grade/Scale Name: MMG/S-III •No. of Vacancies: 143 •Pay Scale: Rs. 42,020-51,490 •Grade/Scale Name: SMG/S-IV •No. of Vacancies: 05 •Pay Scale: Rs. 50,030-59,170 •Grade/Scale Name: SMG/S-V •No. of Vacancies: 02 •Pay Scale: Rs. 59,170-66,070 |
Job
Location: All
India
|
Eligibility
Criteria for Bank of Baroda Specialist Officers:
|
Educational
Qualification: Candidates
should have passed 2 years full time MBA or equivalent Post
Graduation Degree/Diploma in relevant field from a recognised
university.
|
Age
Limit (as on 01-01-2017):
For JMG/S-I: Minimum 21 years and Maximum 30 yearsFor MMG/S-II: Minimum 25 years and Maximum 35 yearsFor MMG/S-III: Minimum 25 years and Maximum 37 yearsFor SMG/S-IV: Minimum 30 years and Maximum 45 yearsFor SMG/S-V: Minimum 35 years and Maximum 50 years |
Selection
Process: Selection
of candidates will be made on the basis of Online Examination and
Personal Interview.
|
Application
Fee: General/UR/OBC
candidates have to pay Rs. 600 and SC/ST/PWD candidates have to
pay Rs. 100 through online mode using Net-banking/Credit or Debit
Card/IMPS/Mobile Wallet.
|
How
to Apply: Interested
and eligible candidates may apply online through BOB website -
http://www.bankofbaroda.co.in/ - from 14-11-2017 to 08-12-2017.
|
Important Dates: • Starting Date of Online Application: 14-11-2017 • Last Date of Online Application: 08-12-2017 |
Other Jobs:
Junior Clerk-cum-Typist - 150 PostsOffice Assistants recruitment
recruitment of 849 Special Reserve Police Constables.
Recruitment of 1,058 First Division Assistant and Second Division Assistant
Bank of Baroda (BOB) - 427 Specialist Officers recruitment
Public Service Commission (TNPSC)
recruitment of 849 Special Reserve Police Constables.
Karnataka State Police (KSP) has released a notification for the
recruitment of 849 Special Reserve Police Constables. Interested
candidates may check the vacancy details and apply online from
27-11-2017 to 18-12-2017.
More details about KSP Recruitment (2017), including number of vacancies, eligibility criteria, selection procedure, how to apply and important dates, are given below:
More details about KSP Recruitment (2017), including number of vacancies, eligibility criteria, selection procedure, how to apply and important dates, are given below:
| Vacancy
Details: •Post Name: Special Reserve Police Constable •No. of Vacancies: 849 •Pay Scale: Rs. Not Specified |
|||||||||
Job
Location:
Karnataka
|
|||||||||
Eligibility
Criteria for KSP Special Reserve Police Constables:
|
|||||||||
Educational
Qualification: Candidates
should have passed SSLC-CBSE, SSLC-ICSE, SSLC-SSC, SSLC-State
Board, SSLC-Equivalent.
|
|||||||||
Age
Limit (as on 18-12-2017): Minimum
18 years and Maximum 25 years
|
|||||||||
Age
Relaxation:
|
|||||||||
Selection
Process:
Selection
of candidates will be made on the basis of Written Examination,
Endurance Test and Physical Standard Test.
|
|||||||||
Application
Fee:
General/2A/2B/3A/3B
Candidates have to pay Rs. 250 and SC/ST/CAT-01 Candidates have to
pay Rs. 100 through Bank Challan.
|
|||||||||
How
to Apply:
Interested
and eligible candidates may apply online through KSP website -
http://ksponline.co.in/ - from 27-11-2017 to 18-12-2017.
|
|||||||||
| Important
Dates: • Starting Date of Online Application: 27-11-2017 • Last Date of Online Application: 18-12-2017 • Last Date for Submitting Application Fee: 20-12-2017 |
|||||||||
Other Jobs:Junior Clerk-cum-Typist - 150 PostsOffice Assistants recruitment recruitment of 849 Special Reserve Police Constables. Recruitment of 1,058 First Division Assistant and Second Division Assistant Bank of Baroda (BOB) - 427 Specialist Officers recruitment Public Service Commission (TNPSC) |
Office Assistants recruitment
Madhya
Pradesh Paschim Kshetra Vidyut Vitaran Company Limited (MPWZ) has
released a notification for the recruitment of 193 Office
Assistants. Interested candidates may check the vacancy details
and apply online from 27-11-2017 to 20-12-2017.
More details about MPWZ Recruitment (2018), including number of vacancies, eligibility criteria, selection procedure, how to apply and important dates, are given below: |
| Vacancy
Details: •Post Name: Office Assistant •No. of Vacancies: 193 •Pay Scale: Rs. 5,200-20,200 •Grade Pay: Rs. 2,500 |
Job
Location: Madhya
Pradesh
|
Eligibility
Criteria for MPWZ Office Assistants:
|
Educational
Qualification:
Candidates
should have passed Graduation Degree in any stream or equivalent
from a recognised university.
|
Age
Limit (as on 01-01-2017):
Minimum
21 years and Maximum 40 years
|
Selection
Process:
Selection
of candidates will be made on the basis of Online Examination.
|
Application
Fee (MP Domicile):
General/OBC
Candidates have to pay Rs. 1,000 and SC/ST Candidates have to pay
Rs. 800 through cash at MP Online Kiosk.
|
How
to Apply:
Interested
and eligible candidates may apply online through MPWZ website -
http://www.mpwz.co.in/ - from 27-11-2017 to 20-12-2017.
|
| Important
Dates: • Starting Date of Online Application: 27-11-2017 • Last Date of Online Application: 20-12-2017 • Date of Examination: 05-01-2018 Other Jobs:
SSC Recruitment 2018
மத்திய அரசில் அதிகாà®°ி பணிகள் Goods Guard recruitment Junior Engineers recruitment |
Recruitment of 1,058 First Division Assistant and Second Division Assistant
Karnataka
Public Service Commission (KPSC) has released a notification for
the recruitment of 1,058 First Division Assistant and Second
Division Assistant. Interested candidates may check the
eligibility criteria and apply online from
More details about KPSC Recruitment (2017), including number of vacancies, eligibility criteria, selection procedure, how to apply and important dates, are given below: |
|||||||||
| Vacancy
Details: •Post Name: First Division Assistant •No. of Vacancies: 507 •Pay Scale: Rs. 14,550-26,700 •Post Name: Second Division Assistant •No. of Vacancies: 551 •Pay Scale: Rs. 11,600-21,000 |
|||||||||
Job
Location: Karnataka
|
|||||||||
Eligibility
Criteria for KPSC First and Second Division Assistants:
|
|||||||||
Educational
Qualification: Candidates
must have passed Bachelor’s Degree in any stream and have
computer knowledge with one-year certificate course of Computers
from an institution recognised by the Government of Karnataka.
|
|||||||||
Age
Limit: Minimum
18 years and Maximum 35 years
|
|||||||||
Age
Relaxation:
|
|||||||||
Selection
Process: Selection
of candidates will be made on the basis of Preliminary Exam, Main
Exam and Personality Test.
|
|||||||||
Application
Fee: General
Candidates have to pay Rs. 300 and 2A/2B/3A/3B Category Candidates
have to pay Rs. 150 through e-Payment from Post Office. SC/ST
candidates don’t have to pay any fee.
|
|||||||||
How
to Apply: Interested
and eligible candidates may apply online through KPSC website -
http://www.kpsc.kar.nic.in/ - from
|
|||||||||
| Important
Dates: • Starting Date of Online Application: • Last Date of Online Application: • Last Date for Payment of Application Fee: Other Jobs:Junior Clerk-cum-Typist - 150 PostsOffice Assistants recruitment recruitment of 849 Special Reserve Police Constables. Recruitment of 1,058 First Division Assistant and Second Division Assistant Bank of Baroda (BOB) - 427 Specialist Officers recruitment Public Service Commission (TNPSC) |
Sunday, November 12, 2017
GE8161 Problem solving and python programming lab Manual
NEHRU INSTITUTE OF ENGINEERING AND TECHNOLOGY
(Approved by AICTE, New
Delhi and affiliated to Anna
University )
NAME
: _____________________________________________________
REG. NO. : _____________________________________________________ Branch : _____________________________________________________
SUBJECT CODE & TITLE :
|
LABORATORY
CONTENTS
Sl.No.
|
Date
|
Name of the Experiment
|
Page No.
|
Signature
|
1
|
Compute the GCD of two numbers.
|
|||
2
|
Find
the square root of a number (Newton’s method)
|
|||
3
|
Exponentiation
(power of a number)
|
|||
4
|
Find
the maximum of a list of numbers
|
|||
5(a)
|
Linear
search
|
|||
5(b)
|
Binary
search
|
|||
6(a)
|
Selection
sort
|
|||
6(b)
|
Insertion
sort
|
|||
7
|
Merge
sort
|
|||
8
|
First
n prime numbers
|
|||
9
|
Multiply
matrices
|
|||
10
|
Programs
that take command line arguments (word count)
|
|||
11
|
Find
the most frequent words in a text read from a file
|
|||
12
|
Simulate
elliptical orbits in Pygame
|
|||
13
|
Simulate
bouncing ball in Pygame
|
Date:
|
GCD OF TWO NUMBERS
|
Aim:
To write a Python program to find GCD
of two numbers.
Algorithm:
1.
Define
a function named computeGCD()
2.
Find
the smallest among the two inputs x and y
3.
Perform
the following step till smaller+1
Check if ((x % i == 0) and (y % i ==
0)), then assign GCD=i
4.
Print
the value of gcd
Program:
def computeGCD(x, y):
if x > y:
smaller = y
else:
smaller = x
for i in range(1, smaller+1):
if((x % i == 0) and (y % i == 0)):
gcd = i
return gcd
num1 = int(input("Enter first number: "))
num2
= int(input("Enter second number: "))
print("The GCD. of",
num1,"and", num2,"is", computeGCD(num1, num2))
Sample output :
The GCD of 54 and 24 is 6
Result:
Thus the Python program to compute GCD
of two numbers is executed successfully and the output is verified.
Date:
|
SQUARE ROOT OF A NUMBER
|
Aim:
To write a Python Program to find the
square root of a number by Newton’s Method.
Algorithm:
1. Define a function named newtonSqrt().
2. Initialize approx as 0.5*n and better
as 0.5*(approx.+n/approx.)
3. Use a while loop with a condition
better!=approx to perform the following,
i. Set approx.=better
ii. Better=0.5*(approx.+n/approx.)
4. Print the value of approx
Program:
def newtonSqrt(n):
approx = 0.5 * n
better = 0.5 * (approx + n/approx)
while better != approx:
approx = better
better = 0.5 * (approx + n/approx)
return approx
print('The square root is'
,newtonSqrt(81))
The square root is 9
Result:
Thus the Python program for finding the
square root of a given number by Newton’s Method is executed successfully and
the output is verified.
EXPONENTIATION OF A NUMBER
|
|
Date:
|
|
To write a Python program to find the
exponentiation of a number.
Algorithm:
1.
Define
a function named power()
2.
Read
the values of base and exp
3.
Use
‘if’ to check if exp is equal to 1 or not
i. if exp is equal to 1, then return base
ii.if exp is not equal to 1, then
return (base*power(base,exp-1))
4.
Print
the result
Program:
def power(base,exp):
if(exp==1):
return(base)
if(exp!=1):
return(base*power(base,exp-1))
base=int(input("Enter base:
"))
exp=int(input("Enter exponential
value: "))
print("Result:",power(base,exp))
Enter base: 7
Enter exponential value: 2
Result:49
Result:
Thus the Python program to find the
exponentiation of a number is executed successfully and the output is verified.
|
Date:
|
FINDING
MAXIMUM FROM A LIST OF NUMBERS
|
Aim:
To write a Python Program to find the
maximum from a list of numbers.
Algorithm:
1.
Create
an empty list named l
2.
Read
the value of n
3. Read the elements of the list until n
4. Assign l[0] as maxno
5. If l[i]>maxno then set maxno=l[i]
6. Increment i by 1
7. Repeat steps 5-6 until i<n
8. Print the value of maximum number
Program:
l=[]
n=int(input("enter the upper
limit"))
for i in range(0,n):
a=int(input("enter the
numbers"))
l.append(a)
maxno=l[0]
for i in range(0,len(l)):
if l[i]>maxno:
maxno=l[i]
print("The maximum number is
%d"%maxno)
Enter the upper limt 3
Enter the numbers 6
Enter the numbers 9
Enter the numbers 90
The maximum number is 90
Result:
Thus a Python Program to find the
maximum from the given list of numbers is successfully executed and the output
is verified.
Date:
|
LINEAR SEARCH
|
Aim:
To write a Python Program to perform
Linear Search
Algorithm:
1. Read n elements into the list
2. Read the element to be searched
3. If alist[pos]==item, then print the
position of the item
4. Else increment the position and repeat
step 3 until pos reaches the length of the list
Program:
def search(alist,item):
found=False
for i in range(n):
if
alist[i]==item:
found=True
print("element found in position",i)
if(found==False):
print("not found")
a=[]
n=int(input("enter upper limit"))
for i in range(0,n):
e=int(input("enter the elements"))
a.append(e)
x=int(input("enter element to search"))
Output:
enter upper limit3
enter the elements12
enter the elements21
enter the elements41
enter element to search21
element found in position 1
Result:
Thus the Python Program to perform
linear search is executed successfully and the output is verified.
Date:
|
BINARY SEARCH
|
Aim:
To write a Python Program to perform
binary search.
Algorithm:
1.Read the search element
2.Find the middle element in the sorted
list
3.Compare the search element with the
middle element
i. if both are matching, print element
found
ii. else then check if the search element
is smaller or larger than the middle element
4.If the search element is smaller than
the middle element, then repeat steps 2 and 3 for the left sublist of the
middle element
5.If the search element is larger than
the middle element, then repeat steps 2 and 3 for the right sublist of the
middle element
6.Repeat the process until the search
element if found in the list
7.If element is not found, loop
terminates
Program:
def bsearch(alist,item):
first=0
last=len(alist)-1
found=False
for i in range(n):
mid=(first+last)//2
if
alist[mid]==item:
found=True
print("element found in position",mid)
break
elif
item<alist[mid]:
last=mid-1
else:
first=mid+mid-1
if(found==False):
print('not
found')
a=[]
n=int(input("enter upper limit"))
for i in range(0,n):
e=int(input("enter the elements"))
a.append(e)
x=int(input("enter element to search"))
bsearch(a,x)
Output:
enter upper limit3
enter the elements12
enter the elements52
enter the elements65
enter element to search52
element found in position 1
Result:
Thus the Python Program to perform
binary search is executed successfully and the output is verified
Date:
|
SELECTION SORT
|
Aim:
To write a Python Program to perform
selection sort.
Algorithm:
1. Create a function named selectionsort
2.
Initialise
pos=0
3. If alist[location]>alist[pos] then
perform the following till i+1,
4. Set pos=location
5. Swap alist[i] and alist[pos]
6. Print the sorted list
Program:
def selectionSort(alist):
for i in range(0,n):
for j in
range(i+1,n):
if
alist[j]<alist[i]:
min =
alist[j];
alist[j]
= alist[i];
alist[i]
= min;
alist = []
n=int(input("enter the no of valus in the list"))
for i in range(n):
alist.append(int(input()))
selectionSort(alist)
print(“Sorted List”,alist)
enter the no of valus in the list5
52
12
10
45
65
Sorted List [10, 12, 45, 52, 65]
Result:
Thus the Python Program to perform
selection sort is successfully executed and the output is verified.
|
Date:
|
INSERTION
SORT
|
Aim:
To write a Python Program to perform
insertion sort.
Algorithm:
1. Create a function named insertionsort
2. Initialise currentvalue=alist[index]
and position=index
3. while position>0 and
alist[position-1]>currentvalue, perform the following till len(alist)
4. alist[position]=alist[position-1]
5.
position
= position-1
6.
alist[position]=currentvalue
7. Print the sorted list
Program:
def insertionSort(alist):
for index in range(1,len(alist)):
currentvalue = alist[index]
position = index
while position>0 and
alist[position-1]>currentvalue:
alist[position]=alist[position-1]
position = position-1
alist[position]=currentvalue
alist = [54,26,93,17,77,31,44,55,20]
insertionSort(alist)
print(alist)
[17, 20, 26, 31, 44, 54, 55, 77, 93]
Result:
Thus the Python program to perform
insertion sort is successfully executed and the output is verified.
|
Date:
|
MERGE
SORT
|
Aim:
To write a Python Program to perform
Merge sort.
Algorithm:
1. Create
a function named mergesort
2. Find the mid of the list
3. Assign lefthalf = alist[:mid] and
righthalf = alist[mid:]
4. Initialise i=j=k=0
5. while i < len(lefthalf) and j <
len(righthalf), perform the following if lefthalf[i] < righthalf[j]:
alist[k]=lefthalf[i]
Increment i
else
alist[k]=righthalf[j]
Increment j
Increment k
6.
while
i < len(lefthalf),perform the following alist[k]=lefthalf[i]
7. while j < len(righthalf), perform
the following alist[k]=righthalf[j]
Increment j Increment k
8. Print the sorted list
def mergeSort(alist):
if len(alist)>1:
mid = len(alist)//2 lefthalf =
alist[:mid] righthalf = alist[mid:] mergeSort(lefthalf) mergeSort(righthalf)
i=j=k=0
while i < len(lefthalf) and j < len(righthalf):
if lefthalf[i] < righthalf[j]:
alist[k]=lefthalf[i]
i=i+1
else:
alist[k]=righthalf[j]
j=j+1
k=k+1
while i < len(lefthalf):
alist[k]=lefthalf[i]
i=i+1
k=k+1
while
j < len(righthalf): alist[k]=righthalf[j]
j=j+1
k=k+1
alist = [54,26,93,17,77,31,44,55,20]
mergeSort(alist)
print(alist)
[17, 20, 26, 31, 44, 54, 55, 77, 93]
Result:
Thus the Python program to perform
merge sort is successfully executed and the output is verified
|
Date:
|
FIRST
N PRIME NUMBERS
|
Aim:
To write a Python program to find first
n prime numbers.
Algorithm:
1. Read the value of n
2. for num in range(0,n + 1), perform the
following
3. if num%i is 0 then break else print the
value of num
4. Repeat step 3 for i in range(2,num)
Program:
n = int(input("Enter the upper
limit: "))
print("Prime numbers are")
for num in range(0,n + 1):
# prime numbers are greater than 1 if num
> 1:
for i in range(2,num): if (num % i) ==
0:
break
else:
print(num)
Enter the upper limit:10
Prime numbers are
2
3
5
7
Result:
Thus the Python Program to find the
first n prime numbers is executed successfully and the output is verified.
Aim:
To write a Python program to multiply
matrices.
Algorithm:
1. Define two matrices X and Y
2. Create a resultant matrix named
‘result’
3. for i in range(len(X)):
i. for j in range(len(Y[0])):
a) for k in range(len(Y))
b)
result[i][j]
+= X[i][k] * Y[k][j]
4. for r in result, print the value of r
Program:
X = [[12,7,3],
[4 ,5,6],
[7 ,8,9]]
Y = [[5,8,1,2],
[6,7,3,0],
[4,5,9,1]]
result = [[0,0,0,0],
[0,0,0,0],
[0,0,0,0]]
for i in range(len(X)):
for j in range(len(Y[0])):
for k in range(len(Y)):
result[i][j] += X[i][k] * Y[k][j]
for r in result:
print(r)
Output:
[114, 160, 60, 27]
[74, 97, 73, 14]
[119, 157, 112, 23]
Result:
Thus the Python program to multiply
matrices is executed successfully and the output is verified.
Date:
|
COMMAND LINE ARGUMENTS(WORD COUNT)
|
Aim:
To write a Python program for command line arguments.
Algorithm:
1. Add arguments to find the words and
lines
2. Add the filename as argument
3. Parse the arguments to get the values
4. Format and print the words and lines
Program:
parser=argparse.ArgumentParser()
parser.add_argument('--words','-w',action='store_true')
parser.add_argument('--lines','-l',action='store_true')
parser.add_argument('filename')
args=parser.parse_args()
if args.words:
print("words
{}".format(print_words(args.filename))
elif args.lines:
print("lines {}".format(print_lines(args.filename))
else:
print ("words
{}".format(print_words(args.filename))
print("lines
{}".format(print_lines(args.filename))
python main.py –i input.txt
words 23
lines 1
Result:
Thus the Python program for command
line arguments is executed successfully and the output is verified.
Date:
|
FINDING MOST FREQUENT WORDS IN A TEXT
READ FROM A FILE
|
Aim:
To write a Python program to find the
most frequent words in a text read from a file.
Algorithm:
1. Read the filename
2. Open the file in read mode
3. Read each line from the file to count
the lowers and words
4. Read each line from the file to replace the
punctuations
5. Split each line into words and count
them
6. Print the words and counts
Program:
def main():
filename=raw_input("enter the
file").strip()
infile=open(filename,"r")
wordcounts={}
for line in infile:
processLine(line.lower(),wordcounts)
pairs=list(wordcounts.items())
items=[[x,y] for (y,x) in pairs]
items.sort()
for i in
range(len(items)-1,len(items)-11,-1):
print(items[i][1]+"\t"+str(items[i][0]))
def processLine(line,wordcounts):
line=replacePunctuations(line)
words=line.split()
for word in words:
if word in wordcounts:
wordcounts[word]+=1
else:
wordcounts[word]=1
def replacePunctuations(line):
for ch in line:
if ch in
"~@#$%^&*()_-+=<>?/.,:;!{}[]''":
line=line.replace(ch," ")
return line
main()
Enter a filename:a.txt
Hi 1
How 1
Are 1
You 1
Result:
Thus the Python program to find the
most frequent words in a text read from a file is executed successfully and the
output is verified.
Date:
|
SIMULATE
ELLIPTICAL ORBITS IN PYGAME
|
Aim:
To write a Python program to simulate
elliptical orbits in Pygame.
Algorithm:
1. Import the required packages
2. Set up the colours for the elliptical
orbits
3. Define the parameters to simulate
elliptical orbits
4. Display the created orbits
Program:
import math
import random
import pygame
class Particle ():
def __init__ (self, x, y,
colour=0x000000):
self.x = x
self.y = y
self.vx = 0
self.vy = 0
self.colour = colour
def apply_gravity (self, target):
dsqd = (self.x - target.x) ** 2 +
(self.y - target.y) ** 2
#g = G*m/dsqd * normalized (self -
target)
if dsqd == 0:
return
self.vx += -1 / dsqd * (self.x -
target.x) / dsqd ** 0.5
self.vy += -1 / dsqd * (self.y -
target.y) / dsqd ** 0.5
def update (self):
self.x += self.vx
self.y += self.vy
pygame.init()
window = pygame.display.set_mode ((600,
400))
main_surface = pygame.Surface ((600,
400))
colours = [0x000000, 0x111111,
0x222222, 0x333333, 0x444444, 0x555555, 0x666666, 0x777777, 0x888888, 0x999999,
0xaaaaaa, 0xbbbbbb] + [0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF,
0x00FFFF, 0x888888, 0xFFFFFF, 0x808000, 0x008080, 0x800080, 0x800000]
#colours = [0xFF0000, 0x00FF00,
0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF, 0x888888,
0xFFFFFF, 0x808000, 0x008080, 0x800080,
0x800000] particles = [Particle (200, 100, colours [i]) for i in range (20)]
earth = Particle (200, 200)
for i, p in enumerate (particles):
p.vx = i / 100
while (True):
# main_surface.fill(0x000000)
pygame.draw.circle (main_surface,
0x00FF00, (earth.x, earth.y), 5, 2)
for p in particles:
p.apply_gravity (earth)
p.update ()
pygame.draw.circle (main_surface,
p.colour, (int (p.x), int (p.y)), 5, 2)
window.blit(main_surface, (0, 0))
pygame.display.flip()

Result:
Thus the Python Program to simulate
elliptical orbits using Pygame is executed successfully and the output is
verified.
Date:
|
SIMULATE BOUNCING BALL USING PYGAME
|
Aim:
To write a Python program to bouncing
ball in Pygame.
Algorithm:
1. Import the required packages
2. Define the required variables
3. Define the screen space to display
the bouncing balls in that space
Program:
import sys
import pygame
pygame.init()
size = width, height = 320, 240
speed = [2, 2]
black = 0, 0, 0
screen = pygame.display.set_mode(size)
ball =
pygame.image.load('C:\\Users\\admin\\Desktop//ball.jpg')
ballrect = ball.get_rect()
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
ballrect = ballrect.move(speed)
if ballrect.left < 0 or
ballrect.right > width:
speed[0] = -speed[0]
if ballrect.top < 0 or
ballrect.bottom > height:
speed[1] = -speed[1]
screen.fill(black)
screen.blit(ball, ballrect)
pygame.display.flip()
Output:

Result:
Subscribe to:
Comments (Atom)