encode_decode.py

# Numtolet lettonum or quit x numtolet lettonum or quit

• Test Prep
• 4

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

>? (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= ""

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

#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
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern