Guest User

Untitled

a guest
Nov 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. def isValidStudentIDFormat(stid):
  2.  
  3. # studentID must have a length of 9
  4. if(len(stid) != 9):
  5. # return the invalid reason
  6. return "Length of Student ID is not 9"
  7.  
  8. # studentID must starts with a letter S
  9. if(stid[0] != 'S'):
  10. # return the invalid reason
  11. return "First letter is not S"
  12.  
  13. # studentID must contains 7 numbers between the two letters
  14. for i in range(1,8):
  15. # anything smaller than 0 or bigger than 9 would not be valid.
  16. # so does a character, will also be invalid
  17. if((stid[i] < '0') or (stid[i] > '9')):
  18. # return the invalid reason
  19. return "Not a number between letters"
  20.  
  21. if((stid[8] < 'A') or (stid[8] > 'Z')):
  22. # return the invalid reason
  23. return "Last letter not a characer"
  24.  
  25. # return True if the format is right
  26. return True
  27.  
  28. def insert_student_record():
  29. #printing the message to ask user to insert a new student into the memory
  30. print("Insert a new student n")
  31. fn = input("Enter first name: ")
  32.  
  33. #check if user entered space
  34. #strip() returns a copy of the string based on the string argument passed
  35. while not fn.strip():
  36. print("Empty input, please enter again")
  37. fn = input("Enter first name: ")
  38.  
  39. ln = input("Enter last name: ")
  40. while not ln.strip():
  41. print("Empty input, please enter again")
  42. ln = input("Enter last name: ")
  43.  
  44. stid = input("Enter student id: ")
  45. while not stid.strip():
  46. print("Empty input, please enter again")
  47. stid = input("Enter student id: ")
  48.  
  49. result = isValidStudentIDFormat(stid)
  50. while (result != True):
  51. print("Invalid student id format. Please check and enter again.")
  52. stid = input("Enter student id: ")
  53. result == True
  54.  
  55. #append the student details to each list
  56. #append first name
  57. fName.append(fn)
  58.  
  59. #append last name
  60. lName.append(ln)
  61.  
  62. #append student id
  63. sid.append(stid)
  64.  
  65. #to check if the new student is in the lists
  66. if stid in sid:
  67. if fn in fName:
  68. if ln in lName:
  69. #then print message to tell user the student record is inserted
  70. print("A new student record is inserted.")
Add Comment
Please, Sign In to add comment