Adding an ID to student name list
SakuraKimiko (4)

Hello

I am trying the following code and to do the follows in PYTHON CODE

  1. I want to start adding student by starting a blank list along with auto generated student ID i.e when once the students joins the site or program, a student no is generated e.g 001 and when the next student joins in , his or her id will become 002 meaning the ID's are generated in series.
  2. How can once create user id using python coding. e.g. once you are joining the program and they ask for personal information. Once the user himself or herself provides a user id (when asked i.e userid=input(""Your user id is:- ")). Can that ID be used to login rather than the name itself

  3. What would be the coding when two people have the same name or user id

Kindly reply all of the above questions in python (as much as possible) because currently I am only learning python.

Thank You for your time

Sakura

You are viewing a single comment. View All
CaptainAnon (48)

@SakuraKimiko

# create a blank list, which will be filled later
student_list = []
# ask if the student is already a member
already_member = input("Are you already a member? ")
if already_member[0].lower == "y":
  memberid = input("Please enter your name or member id: ")
  # do a search for the member
  found_student = False
  for student in student_list:
    if student['id'] == memberid:
      print("Welcome", student['name'])
      found_student = True
      break
  if not found_student:
    print("Could not find that student.")
else:
  become_member = input("Would you like to become a member? ")
  if become_member[0].lower() == "y":
    firstname = input("Please enter your first name. ")
    surname = input("Please enter your surname. ")
    age = int(input("Please enter your age. ")
    id = len(student_list)+1
    student_list.append({'firstname': firstname, surname: 'surname', 'age': age, 'id': id})
    print("You student id is", id)