So this is if i gets to last itteration if i numlen 1

Info icon This preview shows pages 3–4. Sign up to view the full content.

View Full Document Right Arrow Icon
#so this is if i gets to last itteration if i == numlen -1: #use a slice for the last number starting from previous instance of "-" to the end lastiteration= strinput[numbefore:] if lastiteration.isdigit() and strinput < 27: lastiteration= int(strinput[numbefore:]) change+= chr(end+64) return(change) def let_to_num(strinput): #uppercase strinput=strinput.upper() accumulator= 0 numformat= 0 #get length of it letlen= len(inout) total= "" #itterate through the whole string for i in range(letlen): #validate for only letters #wont process it otherwise if strinput[i].isalpha(): #convert it from letter to num numformat= ord(strinput[i])-64 #accumulate it and add a "-" afterwards total+= str(numformat) + "-" #so the last one doesnt have a "-" after it just take everything minus last character total = total[:len(total)-1] return(total)
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
if __name__ == '__main__': answer = input("(n)um_to_let, (l)et_to_num or (q)uit?") answer = str.lower(answer) #repeat question if they dont give a valid answer while answer != "n" and answer != "l" and answer != "q": answer =strinput("(n)um_to_let, (l)et_to_num or (q)uit?") answer = str.lower(answer) #Call the function according to the users initial answer if answer == "l": strinput= input("What string do you want to use your function on?") print(let_to_num(strinput)) elif answer == "n": strinput= input("What string do you want to use your function on?") print(num_to_let(strinput))
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern