I want to know how to repeat a process in python? -


print "you've entered wording system!" print "what words want?"  while false:     word1 = raw_input('enter word:')     word2 = raw_input('enter word:')  print word1 print word2  if len(word1)>len(word2):     word_difference = len(word1) - len(word2)     print word1, "is", word_difference, "letters longer than", word2  elif len(word2)>len(word1):     word_difference = len(word2) - len(word1)     print word2, "is", word_difference, "letters longer than", word1  elif len(word1) == len(word2):     print word1, "has same number of letters as", word2      repeat = raw_input("would enter 2 more words?(y/n)")      if repeat == "y":     y == false 

so want create code repeat word1 = raw input repeat = raw_input(asking fort 2 more words) if question ask "would enter 2 more words" == y , if no == bye!

just put all code in loop, iterates long repeat (initialized "y" stays equal "y"):

print "you've entered wording system!" print "what words want?"  repeat = "y" while repeat == "y":     word1 = raw_input('enter word:')     word2 = raw_input('enter word:')      print word1     print word2      if len(word1)>len(word2):         word_difference = len(word1) - len(word2)         print word1, "is", word_difference, "letters longer than", word2      elif len(word2)>len(word1):         word_difference = len(word2) - len(word1)         print word2, "is", word_difference, "letters longer than", word1      elif len(word1) == len(word2):         print word1, "has same number of letters as", word2          repeat = raw_input("would enter 2 more words?(y/n)") 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -