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

End Semester Performance Name: Guneet Singh Oberai ROLL NO.: BTECH/10240/18 Branch: Eee

The document contains the end semester performance of a student named Guneet Singh Oberai with roll number BTECH/10240/18 studying in the EEE branch. It includes MATLAB and Python programs written by the student to solve various problems. The MATLAB programs check if a number is an EMIRP number and find the location of multiples of seven in a random two dimensional matrix. The Python program analyzes the athlete_events.csv dataset containing Olympic event records to find various statistics related to the 2016 Summer Olympics like number of participant countries, events held, age distribution and medal count.

Uploaded by

Animesh Prasad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views6 pages

End Semester Performance Name: Guneet Singh Oberai ROLL NO.: BTECH/10240/18 Branch: Eee

The document contains the end semester performance of a student named Guneet Singh Oberai with roll number BTECH/10240/18 studying in the EEE branch. It includes MATLAB and Python programs written by the student to solve various problems. The MATLAB programs check if a number is an EMIRP number and find the location of multiples of seven in a random two dimensional matrix. The Python program analyzes the athlete_events.csv dataset containing Olympic event records to find various statistics related to the 2016 Summer Olympics like number of participant countries, events held, age distribution and medal count.

Uploaded by

Animesh Prasad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

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

2. Write a program in MATLAB to print the location of multiples of seven in a


two-dimensional matrix of size 6 x 6. You can assume the matrix contains
random integers in the range 1 - 100. Your answer should return the row and
column of all locations containing multiples of 7 in the matrix.
CODE:
r = randi(100,6)
for row= 1: size(r,1)
for col= 1: size(r,2)
if mod(r(row,col),7) == 0
fprintf("row=%d col= %d \n",row,col)
end
end
end

0.2 PYTHON

Please find uploaded with this assignment a file called athlete_events.csv.


This file contains the record of almost all Olympic events through the years
and the medal-lists. We shall use this dataset to answer a few questions. You
should be able to read the file for use in Python (Hint: You may be required to
split strings on commas i.e. ,).
Before starting off, notice a few oddities in the file ...
1. The first row contains the fields that are there in the file.
2. Strangely most of the string fields in the file contain a redundant double
quotes.
Thus the string Gold is actually stored as "Gold".
3. Like all real life datasets this one too has a lot of missing data and noise.
4. Because of the size of the data, we shall only work with the records
pertaining to the summer Olympic games of 2016.

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)}")

PART2(A) & PART 5


for row in wonMedal:
if row[teamIndex] not in countryWonMedals:
countryWonMedals.append(row[teamIndex])
if row[medalIndex] == 'Gold':
goldMedals += 1
if row[sexIndex] == 'F':
fGoldMedalists += 1
elif row[medalIndex] == 'Silver':
silverMedals += 1
elif row[medalIndex] == 'Bronze':
bronzeMedals += 1
print(f"Total No. of countries won medals : {len(countryWonMedals)-2}")

#-2 because there are 2 countries repeated due to noise in contry


name.(Brazil, Brazil-1 and Indonesia, Indonesia-1)
print(f"No of female gold medalists in 2016 Summer Olympics :
{fGoldMedalists}")
PART 3
ageOfMedalWinners.sort()
plt.hist(ageOfMedalWinners, bins =10)
plt.ylabel('No. of medalists')
plt.xlabel('Age of Medalists')
plt.title('Histogram of Medalists in 2016 Summer Olympics')
plt.show()

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy