Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. import xlwings as xw
  2. import pandas as pd
  3. # python 과 excel 연동 라이브러리
  4.  
  5.  
  6. def show_prompt_menu():
  7. print("""
  8. =====================================================
  9. 1. 성적 입력
  10. 2. 성적 출력
  11. 3. modify
  12. 4. exit program
  13. """)
  14.  
  15.  
  16.  
  17. def show_prompt_close():
  18. print("""
  19. =====================================================
  20. 학번 이름 주소 국어 수학 영어 AVG""")
  21.  
  22.  
  23.  
  24. # save an information about one student
  25. def show_form():
  26. while True:
  27. try:
  28. id = input("학번 입력: ")
  29. name = input("이름을 입력: ")
  30. address = input("주소 입력 입력: ")
  31. kor, eng, math = map(int,input("국어,영어,수학 점수를 입력하세요: ").split() )
  32. break
  33. except (TypeError, ValueError):
  34. print("score should be valid number. Try again.")
  35. student = {
  36. 'ID': id,
  37. 'NAME': name,
  38. 'ADD': address,
  39. 'KOR': kor,
  40. 'ENG': eng,
  41. 'MATH': math,
  42. 'SUM': (kor + eng + math),
  43. 'AVG': float(kor + eng + math) // 3,
  44. }
  45. return student
  46.  
  47.  
  48.  
  49. # printout the whole student information
  50. def display(student_list):
  51. show_prompt_close()
  52. for student in student_list:
  53. print('{ID}\t\t{NAME}\t\t{ADD}\t{KOR}\t\t{ENG}\t\t{MATH}\t\t{AVG}'.format(**student)) # formatting type
  54.  
  55.  
  56. # 만약 학번이나 이름이 기존의 리스트에 있는 값이 라면,
  57. # 해당 딕셔너리를 찾아서 입력하고 싶은 정보를 새로 입력한다.
  58. def modify(student_list):
  59.  
  60. id_name = input("수정하고 싶은 학번이나 이름을 입력: ")
  61. kor, eng, math = map(int, input("국어,영어,수학 점수를 입력하세요: ").split())
  62.  
  63. for i in range(len(student_list) ):
  64. if student_list[i]['ID'] == id_name or student_list[i]['NAME'] == id_name :
  65. student_list[i]['KOR'] = kor
  66. student_list[i]['ENG'] = eng
  67. student_list[i]['MATH'] = math
  68. student_list[i]['SUM'] = kor + eng + math,
  69. student_list[i]['AVG'] = float(kor + eng + math) // 3
  70. print('Information of' ' {} ' 'was changed'.format(student_list[i]['NAME']))
  71. break
  72. else :
  73. print("No name in LIST.")
  74.  
  75. return student_list
  76.  
  77.  
  78. def main():
  79.  
  80. student_list = []
  81.  
  82. while True:
  83. show_prompt_menu()
  84. while True:
  85. try:
  86. select = int(input("what do you want:")) # int 를 하고 안하고가 무슨 차이가 있나. 안하면 if 문 못들어감.
  87. break
  88. except (TypeError, ValueError):
  89. print("that is not a valid number!!")
  90. show_prompt_menu()
  91.  
  92. if select == 1: # save the student information and append to the list
  93. student = show_form()
  94. student_list.append(student)
  95.  
  96. elif select == 2: # show the total student information
  97. display(student_list)
  98.  
  99. elif select == 3:
  100. student_list = modify(student_list)
  101.  
  102. # student_list.append(student)
  103.  
  104. elif select == 4:
  105. break
  106. elif select == 5: # xlwings library testing block
  107. df =pd.DataFrame(student_list)
  108.  
  109. xw.view(df, xw.sheets.active)
  110.  
  111. else:
  112. print("wrong number, try again")
  113.  
  114. if __name__ == '__main__':
  115. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement