I am trying to have the user input two names into variables. These variables will be mixed with scramble-function. Then I want to have them seperated again with the unscramble function but I want the unscramble function to recognise which of the two words was the first input and which the second input.. but I am stuck with scope and have no clue how to solve this correctly.
I appreciate any solution!
a = raw_input("First word please?")
b = raw_input("Second word please?")
def scramble(word1, word2):
if len(word1) > len(word2):
a1 = word1
a2 = word2
else:
a1 = word2
a2 = word1
maxlength = max( len(word1),len(word2) )
magicWord = ""
for x in range(0,maxlength):
magicWord += a1[x]
if x < len(a2)-1:
magicWord += a2[x]
elif x == len(a1)-1:
fin = len(a2)-1
magicWord += a2[fin]
else:
magicWord += "0"
return magicWord
magicWord = scramble(a,b)
print "\nYour magic word is: \""+magicWord+"\"\n"
magicSize = len(magicWord)
def unscramble(magicWord):
z = 0
if z == magicSize:
return False
else:
while unscramble(magicWord):
word1 = ""
word2 = ""
if z % 2 == 1:
if magicWord[z] == "0":
z+= 1
else:
word2 += magicWord[z]
z += 1
else:
if magicWord[z] == "0":
z+= 1
else:
word1 += magicWord[z]
z += 1
return word1
if word1 > word2:
print "First input: " + word1
print "Second input: " + word2
else:
print "First input: " + word2
print "Second input: " + word1
{a : 'first', b: 'second'}and then pass that to your functions.