Numtolet lettonum or quit x numtolet lettonum or quit

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

View Full Document Right Arrow Icon
>? (n)um_to_let, (l)et_to_num or (q)uit? >X (n)um_to_let, (l)et_to_num or (q)uit? >L What string do you want to use your function on? >Hello 8-5-12-12-15 (n)um_to_let, (l)et_to_num or (q)uit? >n What string do you want to use your function on? >8-5-12-12-15 HELLO (n)um_to_let, (l)et_to_num or (q)uit? >q """ ''' First way use an acc ... a string that stores the potential number loop through input if it's a number, store it if it isnt, then that means accumulator has the whole number already Second way use two accumulators one to start the index, antoher has the whole number already the start and end of each number within a string loop through inoput if tis the first number, then its the start if its the last, then it's the end ''' def num_to_let(strinput): numlen= len(strinput) position='' numbefore=0 change= 0 lastiteration= ""
Image of page 2

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

View Full Document Right Arrow Icon
#iterate through every character in string for i in range(numlen): #if statement that takes everything before the "-" and converts that to a letter and stores that in the variable #called letter if strinput[i] == "-": #first have to store position as a string because isdigit function basically works with strings #to identify if theres digit characters within them position= (strinput[numbefore:i]) #have to weed out all the bad characters and numbers that are too big numbefore= i+1 if position.isdigit() and strinput.isdigit() < 27: #change it to an int so it can be added in next step position= strinput[numbefore:i] #in order to convert to number that comp processes must add 64 change+= (chr(position+64)) #this is the last point where there was a '-' so you dont have to restart from beginning #because theres no final "-" the last number has to be processed alternatively
Image of page 3
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