Advertisement
timber101

Pupil Code _String Slicing

Jan 19th, 2022
741
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """
  2. 01  function pupilcode(year,…………………… ,……………………)
  3. 02          yrpart = year.subString(2,2)
  4. 03          snpart = surname.subString(0,……………………)
  5. 04          fnpart = firstname.subString(0,1)
  6. 05           …………………  yrpart + snpart.lower + fnpart.lower
  7. """
  8. def pupilcode(year,surname, firstname):
  9.     yrpart = year[2:4] #0123 => 23
  10.     snpart = surname.lower()[0:5] #"colin gwood"
  11.     fnpart = firstname.lower()[0:1] # first letter
  12.     return yrpart+snpart+fnpart
  13.  
  14. #print(pupilcode("2021","Bloggs","Fred"))
  15.  
  16. year_input = input("Enter year >> ")
  17. sname_input = input("Enter sname >> ")
  18. fname_input = input("Enter fname >> ")
  19.  
  20. print(pupilcode(year_input,sname_input,fname_input))
  21.  
  22. pupilcodecreated = pupilcode(year_input,sname_input,fname_input)
  23.  
  24. file = open("pupilcodes.txt","a") # r read only, w write
  25. file.write(pupilcodecreated +"\n") # \n adds a new line
  26. file.close()
  27.    
  28.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement