Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. import re
  2.  
  3. _LINE_FORMAT_ = "* {:<20} * {:<12} * {:<12} * {:<12} * {:<12} *"
  4. _PATTERN_ = re.compile("^[a-zA-Z]{3,20},\s*?(\d|10)\s*,\s*?(\d|10)\s*,\s*?(\d|10)\s*,\s*?(\d|10)$")
  5. _LINE_WIDTH_ = 84
  6.  
  7.  
  8. class Student:
  9.  
  10.     def __init__(self, pattern):
  11.    
  12.         self.name = pattern.split(",", 1)[0].strip()
  13.         self.grades = [x.strip() for x in pattern.split(",")[1:]]
  14.        
  15.     def __str__(self):
  16.  
  17.         return _LINE_FORMAT_.format(self.name, *self.grades)
  18.  
  19. def print_header():
  20.     print('*' * _LINE_WIDTH_)
  21.     print(_LINE_FORMAT_.format("Nume", "Lab", "Proiect", "Examen", "Nota Finala"))
  22.     print('*' * _LINE_WIDTH_)
  23.    
  24.  
  25. def main():
  26.  
  27.     n = None
  28.     students = []
  29.  
  30.     while type(n) != type(0):
  31.  
  32.         try:
  33.             n = int(raw_input("Numarul de studenti:"))
  34.         except:
  35.             print("Input invalid")
  36.             n = None
  37.            
  38.     current = 0
  39.    
  40.     while current < n:
  41.         data = raw_input("Student {}:".format(current + 1)).strip()
  42.         if re.match(_PATTERN_, data) is None:
  43.             print("Invalid input")
  44.             continue
  45.         else:
  46.             students.append(Student(data))
  47.             current += 1
  48.            
  49.     print_header()
  50.    
  51.     for stud in students:
  52.         print(stud)
  53.        
  54.     print('*' * _LINE_WIDTH_)
  55.  
  56. if __name__ == "__main__":
  57.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement