Python 3.4.2 Write a series of functions that can be used as part of a secret me
ID: 650392 • Letter: P
Question
Python 3.4.2
Write a series of functions that can be used as part of a secret message encoder program. functions you will be writing as well as some sample code that you use use to test your work.
Sample Program
Sample Output
You will need to use a loop to generate the required # of random characters, and you will (obviously) need to use some random number functions as well. Think about the algorithm before you start coding! Draw out the steps you think you need to take on a piece of paper. For example: "Start with the first character in the source word. Then generate 'num' new random characters and concatente these characters. Then move onto the next character in the source word and repeat the process".
Explanation / Answer
import string
import random
def add_letters(original,num):
n=len(original)
scrambled=""
for i in range(n):
scrambled+=original[i]
randomSequence=""
for j in range(num):
randomSequence+=random.choice(string.letters)
scrambled+=randomSequence
return scrambled
original = "Hello!"
for num in range(1,5):
scrambled=add_letters(original,num)
print "Adding "+str(num)+" random characters to "+ original+" -> "+scrambled
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.