title: Modifying lines in a file with Python
body: <p>There is a given file text.txt that contains chapters of a book that are numbered with roman numerals. I need to write a program that rewrites the given file to a new.txt where the numerals are replaced with regular numbers from 1 to 3. In addition, the program should ask a user for an input of a number and print out that specific chapter.</p>
  
  <pre><code>def main():
      found = False
      search=input('Enter a description of a chapter in Roman numerals: ')
      new_num = int(input('Enter a new number: '))
  
      text=open('sentence.txt', 'r')
      new_file=open('new.txt', 'w')
      descr=sentence.readline()
  
      while line!='':
         num=float(sentence.readline())
         descr = descr.rstrip('\n')
  
         if descr == search: #trying to capture the roman numeral
            new_file.write(descr + '\n')
            new_file.write(str(new_num) + '\n') #trying to substitute roman numeral with a number
  
            found=True
         else:
  #writing the original record to the temp file with regular numbers
            new_file.write(descr + '\n')
            new_file(str(new_num) + '\n')
  
         descr=sentence.readline()
      sentence.close()
      new_file.close()
  
      if found:
             print("The file has been rewritten")
      else:
             print('Not found')
  main()
  </code></pre>
  
  <p>So far I tried to substitute an input of 'I' to a regular number and write it to a new file. However, the program keeps giving me errors...</p>
  
  <p>Is there a way not to ask for an input but to substitute only the Roman numerals indicating chapters of the book with regular numbers and rewrite the rest of the text to a new file? Any suggestions how to solve this would be highly appreciated.</p>