Created
January 30, 2019 14:58
-
-
Save Ojha-Shashikant/4a35b16e69f10dc16b61a334550f18ed to your computer and use it in GitHub Desktop.
Sachin runs in 2001.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Count the number of innings Sachin scored less than 25 runs in 2001 | |
import sys | |
import os | |
from math import sum | |
# Fill the missing pieces in the below line to get the list of runs scored by Sachin in 2001. | |
# runs = [ num.strip() for num in open("sachin_runs.csv").read().split() ] | |
# Use the above "runs" list to find out the number of innings Sachin scored less than 25 runs | |
## YOUR CODE GOES HERE ## | |
''' | |
def reading_file(): | |
FH = open("C:\Users\Ojha\Desktop\Sachin_run.csv", 'r+') | |
runs = FH.readlines() | |
FH.close() | |
return runs | |
''' | |
def count_runs_lt_25(runs): | |
cnt = 0 | |
for run in runs: | |
if run < 25: | |
cnt += 1 | |
print("Sachin scored less than 25 ", cnt, " times in 2001.") | |
# A Journalist makes a claim that in 2001, Sachin scored less than 33 runs, in less than 33% of his innings | |
# Write Python code to check the claim made by this Journalist | |
## YOUR CODE GOES HERE ## | |
def check_lt_33(runs): | |
cnt = 0 | |
for run in runs: | |
if run < 33: | |
cnt += 1 | |
total_innings = runs.length() | |
percent_of_innings_lt_33_score = (cnt/total_innings)*100 | |
if percent_of_innings_lt_33_score < 33: | |
print("Journalist's claim was correct. Sachin scored less than 33 runs, in less than 33% of his innings") | |
else: | |
print("Journalist's claim was Incorrect.") | |
# A Commentator then claims that in 2001, Sachin's score on an average, crossed half a century in at least one of every 2 innings. | |
# Write Python code to check the claim made by this Commentator | |
## YOUR CODE GOES HERE ## | |
def average_every_innings(runs): | |
total_runs = math.sum(runs) | |
Average_per_inning = total_runs / runs.length | |
if Average_per_inning >= 50: | |
print("Commentator's claim was correct. Sachin's score on an average, crossed half a century in at least one of every 2 innings.") | |
else: | |
print("Commentator's claim was Incorrect.") | |
if __name__ == "__main__": | |
runs = [ num.strip() for num in open("sachin_runs.csv").read().split() ] | |
count_runs_lt_25(runs) | |
check_lt_33(runs) | |
average_every_innings(runs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment