Write a program that reads file called bballscores.txt containing the score of T
ID: 3804530 • Letter: W
Question
Write a program that reads file called bballscores.txt containing the score of Team A's basketball games. The file will contain two numbers per line (separated by 1 space), corresponding to the number of points Team A scored, and the number of points their opponent scored respectively. Calculate Team A’s record at the end of the season (wins and losses), as well as their overall point differential (The total number of points they scored minus the total number they allowed), and print these values.
Explanation / Answer
input file:
45 23
56 34
67 89
Code:
import os
import sys
import numpy as np
fr = open("input.txt","r")
lines =fr.readlines()
count=0
wincount =0
losscount=0
totalpt=0
for line in lines:
pt1= int(line.split()[0])
pt2= int(line.split()[1])
if pt1 >pt2:
wincount+=1
else:
losscount+=1
totalpt+=pt1
print "total no of wins: "+ str(wincount)
print "total no of losses: "+ str(losscount)
print "total points: "+ str(totalpt)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.