파이썬 8학기 성적 출력 프로그램
파이썬으로 짠 8학기 성적 출력 프로그램입니다. 기능을 더 집어 넣고 싶은데 레포트로 제출해야 되서
국내에 파이썬 자료가 별로 없으니 어떻게 검색해서 들어오신 분들은 참고하시기 바라고~ 만약 저의과
학생들이 보면 변수명만 바꿔서 제출하는 불상사는 없기를 바랍니다 ㅡ,.ㅡ;;; (참고만 하세요;;;)
#This is a main function
def main():
name = raw_input("Enter your name : ")
for num in ('1-1','1-2','2-1','2-2','3-1','3-2','4-1','4-2'):
result = {}
file = open(num, 'r')
for eachLine in file.readlines():
lists = re.split('\s', eachLine)
result[lists[0]] = lists[1]
file.close()
print
print dashes
print name + "`s " + num + " term result"
print dashes
result_sum = 0
result_ave = 0
temp = []
for num1 in result.keys():
file = open(result[num1], 'r')
for eachLine in file.readlines():
lists = re.split('\s', eachLine)
if ( lists[0] == name ):
temp.append(lists[1])
result_sum = result_sum + int(lists[1])
result_ave = (result_sum) / len(temp)
print result[num1] + " : " + make_grade(int(lists[1]))
print dashes
print 'Total score is : %s' % result_sum
print 'Total grade is : %s' % make_grade(int(result_ave))
print dashes
#This function makes a score to grade
def make_grade(score):
unit = ''
if int(95) <= score <= int(100):
unit='A+'
elif int(90) <= score <= int(94):
unit='A'
elif int(85) <= score <= int(89):
unit='B+'
elif int(80) <= score <= int(84):
unit='B'
elif int(75) <= score <= int(79):
unit='C+'
elif int(70) <= score <= int(74):
unit='C'
elif int(65) <= score <= int(69):
unit='D+'
elif int(60) <= score <= int(64):
unit='D'
elif int(0) <= score <= int(59):
unit='F'
return unit
#This function shows a menu
def showmenu():
prompt = """
(R)esult
(Q)quit
Enter choice : """
done = 0
while not done:
chosen = 0
while not chosen:
try:
choice = raw_input(prompt)[0]
except (EOFError, KeyboardInterrupt):
choice = 'q'
print '\nYou picked : [%s]' % choice
if choice not in 'rq':
print 'invalid option, try again'
else :
chosen = 1
if choice == 'q': done = 1
if choice == 'r': result()
#This function is a part of menu
def result():
main()
if __name__ == '__main__':
showmenu()
사용방법
같은 디렉토리 내에 1-1, 1-2 ... 4-1, 4-2 학기 파일이 있어야 함
같은 디렉토리 내에 국어, 영어, 사회 파일이 있어야 함
(만드는 방법은 메모장 으로 확장자 없이 "국어" 저장)
학기 파일 과목 파일
1101 국어 개똥 95
1102 영어 말똥 90
1103 사회 소똥 85
반드시 이런식으로 되어 있어야 함
그럼 이만 ㅎㅎ;;