Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- _LINE_FORMAT_ = "* {:<20} * {:<12} * {:<12} * {:<12} * {:<12} *"
- _PATTERN_ = re.compile("^[a-zA-Z]{3,20},\s*?(\d|10)\s*,\s*?(\d|10)\s*,\s*?(\d|10)\s*,\s*?(\d|10)$")
- _LINE_WIDTH_ = 84
- class Student:
- def __init__(self, pattern):
- self.name = pattern.split(",", 1)[0].strip()
- self.grades = [x.strip() for x in pattern.split(",")[1:]]
- def __str__(self):
- return _LINE_FORMAT_.format(self.name, *self.grades)
- def print_header():
- print('*' * _LINE_WIDTH_)
- print(_LINE_FORMAT_.format("Nume", "Lab", "Proiect", "Examen", "Nota Finala"))
- print('*' * _LINE_WIDTH_)
- def main():
- n = None
- students = []
- while type(n) != type(0):
- try:
- n = int(raw_input("Numarul de studenti:"))
- except:
- print("Input invalid")
- n = None
- current = 0
- while current < n:
- data = raw_input("Student {}:".format(current + 1)).strip()
- if re.match(_PATTERN_, data) is None:
- print("Invalid input")
- continue
- else:
- students.append(Student(data))
- current += 1
- print_header()
- for stud in students:
- print(stud)
- print('*' * _LINE_WIDTH_)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement