title: Program prints individual lines and not whole file
body: <p>This is a homework assignment and i can't seem to figure it out.</p>
  
  <p>"Write a program that asks the user for the name of a file. The program should display only the first five lines of the file's contents. If the file contains less than five lines, it should display the file's entire contents."</p>
  
  <p>Whenever the program reads a file with more then 5 lines it only prints the first 5 lines. However when a file is read with less then 5 lines it should print the whole file but it does not do that. Any help is appreciated.</p>
  
  <pre><code>def file_head_display():
      total = 0
      file = str(input('Enter the name of the file'))
      f_open = open (file, 'r')
      line1 = f_open.readline()
      line2 = f_open.readline()
      line3 = f_open.readline()
      line4 = f_open.readline()
      line5 = f_open.readline()
  
  
  
      for line in f_open:
          amount = int(line)
          total += amount
  
      if total &gt; 5:
          print(line1)
          print(line2)
          print(line3)
          print(line4)
          print(line5)
      else:
          contents = f_open.read()
          print(contents)
  
  
  file_head_display()
  </code></pre>