reversing string in python

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • python101
    New Member
    • Sep 2007
    • 90

    #16
    How can I print the output out(the mutated DNA)? I got error message.

    How can I make the program run without being interrupted (after input the dna and pat, it outputs the result, then it appears the input again,...) when I want it to stop I type 'exit' and 'quit' to make it stop running?

    Comment

    • bartonc
      Recognized Expert Expert
      • Sep 2006
      • 6478

      #17
      Originally posted by python101
      How can I print the output out(the mutated DNA)? I got error message.

      How can I make the program run without being interrupted (after input the dna and pat, it outputs the result, then it appears the input again,...) when I want it to stop I type 'exit' and 'quit' to make it stop running?
      [CODE=python]# Use lots of comments
      # to describe your program

      # put imports at the top
      import sys

      def CheckDNASequenc e(sequence):
      # just a stub
      return True


      # "encapsulat e" using functions
      def GetDNASequence( ): # use descriptive names
      while 1: # alway loop
      seq = raw_input("Ente r a sequence ('q' to quit): ")
      if seq.lower() == "q":
      return # break out of the loop, returning None
      if CheckDNASequenc e(seq): # break out of the loop
      break
      return seq # good practice to put the valid return here

      def GetPattern():
      pat = raw_input("Ente r a pattern: ")
      return pat


      def main():
      while True: # always loop
      seq = GetDNASequence( )
      if seq is None:
      sys.exit()
      print seq
      pat = GetPattern()
      print pat

      if __name__ == "__main__":
      main()[/CODE]

      Comment

      Working...