Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Task 3.1
- By Mark Wu
- @markwu.me
- '''
- # -----------------Welcome screen-----------------
- print("-----------------Task 3.1-----------------")
- print('''
- -----Task 3 Overview-----
- [1] (-----SELECTED-----) Create new records
- [2] (Task 3.2) Check current records
- [3] (Task 3.3) Find member ID
- [4] (Task 3.4) Add new users
- ''')
- # u_choice = input("Which function do you want to choose? Please input its No. >>>")
- # while u_choice not in ['1','2','3','4']:
- # print("Invalid choice. A valid choice would be 1, 2, 3 or 4.")
- # u_choice = input("Which function do you want to choose? Please input its No. >>>")
- # if u_choice == '1':
- # -----------------Task 3.1-----------------
- # The following are the functions used in the program
- # Validation Function from Task 2.2
- def ValidateuserID(instring):
- if len(instring) == 6 and instring[0].isupper() and instring[1:3].islower() and instring[3:].isnumeric():
- return True
- else:
- return False
- def input_name():
- instr = input("Please input member's name >>>") # string
- while not 0 < len(instr) < 25 or instr in (','):
- print("Invalid name. A valid name should be less than 25 characters. Please input again.")
- instr = input("Please input member's name >>>")
- return instr
- def input_id(member_name=''):
- instr = input("Please input member ID for %s >>>" % member_name)
- while not ValidateuserID(instr):
- print("Invalid ID. Please try again.")
- instr = input("Please input member ID for %s >>>" % member_name)
- return instr
- # Initialization
- member_list = [] # List
- # Input member
- flag = True
- while flag:
- mem_name = input_name() # String
- mem_id = input_id(mem_name) # String
- new_member = [mem_name, mem_id] # List
- member_list.append(new_member)
- # Ask if the user want to continue
- to_continue = input("Input 'stop' to save your progress, otherwise please enter anything to continue.")
- if to_continue == 'stop':
- flag = False
- # Create File and store the result
- try:
- with open('record.txt', mode='w') as myfile:
- for each in member_list:
- newline = ','.join(each)
- myfile.write(newline + '\n')
- print('Data successfully stored.')
- except:
- print("Can't create file! Please check file permission.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement