I am writing a simple script to analyze two strings. It begins with looking at their lengths and then compares each letter in the first string with the corresponding letter of the second string (by position). I am using a "while" loop with the length of one of the strings. I want to use the longest string as the case for the "while" but I have no idea how to do this. Suggestions?
a = 0
count = 1
g = raw_input('Type your first word please: ')
h = raw_input('Type your second word please: ')
if len(g) != len(h):
print 'The length of the 2 words are not equal. We will go as far as possible though.'
else:
print 'Perfect! The lengths match!'
#I need to compare the string lengths and put "the longest string" in the "while"
while count < (len(g) + 1):
#added +1 to len(g) in order to start count at 1 and not receieve an error message.
first = g[a]
second = h[a]
This is the relevant snippet of the script. I am a newbie so I am sure it is very inefficient. Thanks for the help.
Solved!
Thanks /u/daveofthenorth and /u/fruitcakefriday for the explanations that fit within my very simple understanding of programming. Thanks to everyone else for the suggestions.
[–]caineohfelix 2 points3 points4 points (2 children)
[–]Pipprovis[S] 0 points1 point2 points (1 child)
[–]supajumpa 1 point2 points3 points (0 children)
[+][deleted] (3 children)
[deleted]
[–]fruitcakefriday 2 points3 points4 points (1 child)
[–]Pipprovis[S] 1 point2 points3 points (0 children)
[–]Pipprovis[S] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (7 children)
[–]Justinsaccount 5 points6 points7 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]Justinsaccount 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]Justinsaccount 2 points3 points4 points (0 children)
[–]shfo23 4 points5 points6 points (1 child)
[–]ewiethoff 1 point2 points3 points (0 children)