|
Post by madasmatt4 on May 16, 2017 13:30:55 GMT
How would you do the Edit() and View() subroutine i know you need to do something like names[ ] and append the names or something but help me please. This is what I have done so far:
def Add():
Forename = input("Enter Forename : ")
Surname = input("Enter Surname : ")
def Edit():
def View():
def Menu():
print("Welcome Mr Leeman to the register!")
print("We have 3 options for you enter (1)To Add, (2)To Edit, (3)To View")
Choice = input("Decision: ")
if Choice == 1:
Add()
pass
if Choice == 2:
Edit()
pass
if Choice == 3:
View()
pass
print("Welcome to the something edit this later!")
Tries = 5
while Tries > 0:
ID = input("Enter your ID name : ")
Password = input("Enter your password : ")
if ID == "Leeman" and Password == "LifeIsAwesome123":
print("successfully logged in")
print(Menu())
break
else:
Tries = Tries - 1
print("Incorrect. you have", Tries,"left.")
|
|
|
Help!
May 16, 2017 15:13:44 GMT
Post by Josh on May 16, 2017 15:13:44 GMT
Hi madasmatt4 , To start, you should make sure that you have an array or list that contains student data. Looking at the requirements which can be found here, I would recommend that you store student data in a . txt file. For example, you could store something that looks like this 0001;Smith;John;01/01/2002;1 Programming Dr.;01234 567890;M;Oak;johnsmith@treeroadschool.co.uk 0002;Smith;Jane;02/02/2002;2 Coding Ave.;09876 543210;F;Oak;janesmith@treeroadschool.co.uk To split the data into lists, you should use . split() and create a two-dimensional array. studentlist = [] for i in txtFile.split("\n"): #split by newline studentlist += [i.split(";")] #split by semicolon print(studentlist)
> [['0001', 'Smith', 'John', '01/01/2002', '1 Programming Dr.', '01234 567890', 'M', 'Oak', 'johnsmith@treeroadschool.co.uk'], ['0002', 'Smith', 'Jane', '02/02/2002', '2 Coding Ave.', '09876 543210', 'F', 'Oak', 'janesmith@treeroadschool.co.uk']]
print(studentlist[0])
> ['0001', 'Smith', 'John', '01/01/2002', '1 Programming Dr.', '01234 567890', 'M', 'Oak', 'johnsmith@treeroadschool.co.uk']
print(studentlist[0][2])
> John
You can now iterate through users to view and edit. Using .join() will allow you to convert a string into a string split up by any character of your choice. For example, print(" | ".join(studentlist[0]))
> 0001 | Smith | John | 01/01/2002 | 1 Programming Dr. | 01234 567890 | M | Oak | johnsmith@treeroadschool.co.uk In this case, we have joined the list with " | ". Hopefully, this helps!
|
|