End Semester Performance Name: Guneet Singh Oberai ROLL NO.: BTECH/10240/18 Branch: Eee
End Semester Performance Name: Guneet Singh Oberai ROLL NO.: BTECH/10240/18 Branch: Eee
End Semester Performance Name: Guneet Singh Oberai ROLL NO.: BTECH/10240/18 Branch: Eee
0.1 MATLAB
1. Write a program in MATLAB to test whether a number is an EMIRP. An
EMIRP is a prime whose reverse is also a prime e.g. 79 <=> 97.
CODE:
x=input("Enter number :")
c=0;
if x==0| x==1
disp("Wrong case")
end
if isprime(x)
c=c+1;
end
rev_x = str2num(fliplr(num2str(x)));
if isprime(rev_x)
c=c+1;
end
if c==2
disp('number is emirp')
else
disp('not emirp')
end
0.2 PYTHON
Given this dataset can you answer the following questions specific to the
Summer 2016 games:
1. How many records are there in the dataset from the summer 2016 games?
2. How many countries won medals and how many different events were held
during the 2016 games?
3. Plot a histogram for the age of the medal winners using 10 bins.
4. Plot a bar chart showing how many Gold, Silver and Bronze medals were
awarded
in 2016?
5. How many females won Gold medals in 2016?
CODE:
import csv
from matplotlib import pyplot as plt
fields = []
allData = []
reqData = []
wonMedal = []
ageOfMedalWinners = []
countryWonMedals = []
eventsHeld = []
goldMedals = 0
silverMedals = 0
bronzeMedals = 0
fGoldMedalists = 0
filename = 'athlete_events.csv'
with open(filename,'r') as csvFile:
csvreader = csv.reader(csvFile, quoting = csv.QUOTE_ALL, delimiter = ',')
fields = next(csvreader)
gamesIndex = fields.index('Games')
medalIndex = fields.index('Medal')
eventIndex = fields.index('Event')
teamIndex = fields.index('Team')
ageIndex = fields.index('Age')
sexIndex = fields.index('Sex')
PART1
for row in csvreader:
allData.append(row)
if row[gamesIndex] == '2016 Summer':
reqData.append(row)
print(f"No. of records of 2016 Summer Olympics : {len(reqData)}")
PART2(B)
for row in reqData:
if row[medalIndex] != 'NA':
wonMedal.append(row)
ageOfMedalWinners.append(row[ageIndex])
if row[eventIndex] not in eventsHeld:
eventsHeld.append(row[eventIndex])
print(f"No. of different events held in 2016 Summer
Olympics:{len(eventsHeld)}")
PART4
medals = ('Gold','Silver','Bronze')
noOfMedals = [goldMedals , silverMedals, bronzeMedals]
plt.bar(medals, noOfMedals, align='center')
plt.ylabel('No. Of Medals')
plt.xlabel('Type Of Medal')
plt.title('Medals awarded in 2016 Summer Olympics')
plt.show()