Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import xlwings as xw
- import pandas as pd
- # python 과 excel 연동 라이브러리
- def show_prompt_menu():
- print("""
- =====================================================
- 1. 성적 입력
- 2. 성적 출력
- 3. modify
- 4. exit program
- """)
- def show_prompt_close():
- print("""
- =====================================================
- 학번 이름 주소 국어 수학 영어 AVG""")
- # save an information about one student
- def show_form():
- while True:
- try:
- id = input("학번 입력: ")
- name = input("이름을 입력: ")
- address = input("주소 입력 입력: ")
- kor, eng, math = map(int,input("국어,영어,수학 점수를 입력하세요: ").split() )
- break
- except (TypeError, ValueError):
- print("score should be valid number. Try again.")
- student = {
- 'ID': id,
- 'NAME': name,
- 'ADD': address,
- 'KOR': kor,
- 'ENG': eng,
- 'MATH': math,
- 'SUM': (kor + eng + math),
- 'AVG': float(kor + eng + math) // 3,
- }
- return student
- # printout the whole student information
- def display(student_list):
- show_prompt_close()
- for student in student_list:
- print('{ID}\t\t{NAME}\t\t{ADD}\t{KOR}\t\t{ENG}\t\t{MATH}\t\t{AVG}'.format(**student)) # formatting type
- # 만약 학번이나 이름이 기존의 리스트에 있는 값이 라면,
- # 해당 딕셔너리를 찾아서 입력하고 싶은 정보를 새로 입력한다.
- def modify(student_list):
- id_name = input("수정하고 싶은 학번이나 이름을 입력: ")
- kor, eng, math = map(int, input("국어,영어,수학 점수를 입력하세요: ").split())
- for i in range(len(student_list) ):
- if student_list[i]['ID'] == id_name or student_list[i]['NAME'] == id_name :
- student_list[i]['KOR'] = kor
- student_list[i]['ENG'] = eng
- student_list[i]['MATH'] = math
- student_list[i]['SUM'] = kor + eng + math,
- student_list[i]['AVG'] = float(kor + eng + math) // 3
- print('Information of' ' {} ' 'was changed'.format(student_list[i]['NAME']))
- break
- else :
- print("No name in LIST.")
- return student_list
- def main():
- student_list = []
- while True:
- show_prompt_menu()
- while True:
- try:
- select = int(input("what do you want:")) # int 를 하고 안하고가 무슨 차이가 있나. 안하면 if 문 못들어감.
- break
- except (TypeError, ValueError):
- print("that is not a valid number!!")
- show_prompt_menu()
- if select == 1: # save the student information and append to the list
- student = show_form()
- student_list.append(student)
- elif select == 2: # show the total student information
- display(student_list)
- elif select == 3:
- student_list = modify(student_list)
- # student_list.append(student)
- elif select == 4:
- break
- elif select == 5: # xlwings library testing block
- df =pd.DataFrame(student_list)
- xw.view(df, xw.sheets.active)
- else:
- print("wrong number, try again")
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement