Search code examples
pythongoogle-sheets-apigspread

How Do I make student code not overwrite the previous code by changing the cell it is put into


users = []
firstname = input("what is your first name:")
lastname = input ("what is your last name:")
year = input ("what year did you join the school:")
inital = firstname[0:1]

code = ( year+lastname+inital)
for i in users:
 if code == i:
  print("This username already exists",code)
  code = code+"#"
print("-"*30)
print ("your student code is:",code)
print("-"*30)
users.append(code)

sheet.update("A3",code)

**I want to make the cell that the student code is put into change each time it is run

currently i can only make it keep overwriting in A3**


Solution

  • Hi as stated in the documentation here you can use the method that appends a new row to the spread sheet so the students are listed one after another, one per line.

    the code to update is:

    sheet.update("A3",code)
    

    replace it with:

    sheet.append_row([code])
    

    Note:

    the string code must be put into a list as append_row takes a list of values.