from Student import Student
import matplotlib.pyplot as plt
def barChart():
studentList=[]
studentList.append(Student(50123456,'lam tai man',710,60.0))
studentList.append(Student(50223456,'li tai man',60.0,90.5))
studentList.append(Student(50323456,'wong tai man',34.5,30.0))
studentList.append(Student(50423456,'ng tai man',90.5,70.0))
studentList.append(Student(50523456,'lau tai man',86.0,92.4))
studentList.append(Student(50623456,'chui tai man',70.0,64.5))
studentList.append(Student(50723456,'lim tai man',64.5,60.0))
studentList.append(Student(50823456,'pok tai man',37.5,35.50))
studentList.append(Student(50923456,'kim tai man',92.4,60.0))
studentList.append(Student(50023456,'tsang tai man',15.0,20.0))
studentList.append(Student(50999999,'chan peter',100.00,80.00))
gradeFeq={'A':0,'B':0,'C':0,'D':0,'E':0,'F':0}
for e in studentList:
mark=e.overall()
if mark > 75:
gradeFeq['A'] += 1
elif mark > 65 and mark < 75:
gradeFeq['B'] += 1
elif mark > 50 and mark < 65:
gradeFeq['C'] += 1
elif mark > 40 and mark < 50:
gradeFeq['D'] += 1
else:
gradeFeq['F'] += 1
fig = plt.figure(figsize=(8,6)) # width x height in inches
ax1 = fig.add_subplot(111) # 1 row 1 columns, column 1
ax1.bar(['A','B','C','D','F'],
[gradeFeq['A'],gradeFeq['B'],gradeFeq['C'],
gradeFeq['D'],gradeFeq['F']]) # vertical bar charts
plt.show()
def main():
instructions = """\nEnter one of the following:
1 to read and print the contents of input data file
2 to print all students overall mark
3 to print all students whose mark less than 40
4 to plot distribution of grade
Q to end \n"""
while True:
print (instructions)
choice = input( "Enter 1 to 5 " )
if choice == "1":
pass
elif choice == "2":
pass
elif choice == "3":
pass
elif choice == "4":
barChart()
elif choice == "Q":
break
print ("End Grade Processing App")
if __name__ == "__main__":
main()
import xmltodict
import urllib.request
userCurrency = input('Enter Currency Code : ')
fileIn=urllib.request.urlopen('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml')
byteStr = fileIn.read()
lines=byteStr.decode('utf-8')
dl=xmltodict.parse(lines)
if userCurrency == 'XDR':
for e in dl['gesmes:Envelope']['Cube']['Cube']['Cube']:
if e.get('@currency') == 'JPY':
jpyRate = e.get('@rate')
if e.get('@currency') == 'CNY':
cnyRate = e.get('@rate')
if e.get('@currency') == 'GBP':
gbpRate = e.get('@rate')
if e.get('@currency') == 'USD':
usaRate = e.get('@rate')
userCurrencyRate = "{:.4f}".format(1/(0.38671 + 11.9 / float(jpyRate) + 1.0174 / float(cnyRate) +
0.085946 / float(gbpRate) + 0.58252 / float(usaRate)))
else:
for e in dl['gesmes:Envelope']['Cube']['Cube']['Cube']:
if e.get('@currency') == userCurrency:
userCurrencyRate = e.get('@rate')
print("On " + dl['gesmes:Envelope']['Cube']['Cube']['@time'] +
" One euro is " + userCurrencyRate + ' ' + userCurrency)
import xml.etree.ElementTree as ET
import urllib.request
userCurrency = input('Enter Currency Code : ')
fileIn = urllib.request.urlopen("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml")
byteStr = fileIn.read()
dataStr = byteStr.decode('utf-8')
dataTree = ET.fromstring(dataStr)
if userCurrency == 'XDR':
for element in dataTree[2][0]:
if element.attrib['currency'] == 'JPY':
jpyRate = element.attrib['rate']
if element.attrib['currency'] == 'CNY':
cnyRate = element.attrib['rate']
if element.attrib['currency'] == 'GBP':
gbpRate = element.attrib['rate']
if element.attrib['currency'] == 'USD':
usaRate = element.attrib['rate']
userCurrencyRate = "{:.4f}".format(1/(0.38671 + 11.9 / float(jpyRate) + 1.0174 / float(cnyRate) +
0.085946 / float(gbpRate) + 0.58252 / float(usaRate)))
else:
for element in dataTree[2][0]:
if element.attrib['currency'] == userCurrency:
userCurrencyRate = element.attrib['rate']
print("On " + dataTree[2][0].attrib['time'] + " One euro is " + userCurrencyRate + ' ' + userCurrency)