title: Optimization on Python: How do I simplify this code?
body: <p>I'm new to python, I was trying to solve this optimization problem:</p>
  
  <pre><code>    In How many possible ways can I receive 42 emails in 7 days?
  </code></pre>
  
  <p>and I wrote this program in Python to count all the solutions:</p>
  
  <pre><code>n = 42
  print(n, "emails can be received in the following ways:")
  solcount = 0
  for d1 in range (n+1):
      for d2 in range (n+1-d1):
          for d3 in range (n+1-d1-d2):
              for d4 in range (n+1-d1-d2-d3):
                  for d5 in range (n+1-d1-d2-d3-d4):
                      for d6 in range (n+1-d1-d2-d3-d4-d5):
                          for d7 in range (n+1-d1-d2-d3-d4-d5-d6):
                              if d1+d2+d3+d4+d5+d6+d7 == n:
                                  solcount +=1
  print("There are", solcount, "possible solutions")
  </code></pre>
  
  <p>where d1 to d7 are the number of emails received on days 1 to 7 respectively.  </p>
  
  <p>Now, there are two problems to this:  </p>
  
  <ol>
  <li>The runtime is ridiculously high, and I suspect that this algorithm
  is far from optimal.</li>
  <li>The code doesn't allow for me to vary the number of days (like if I were to fix the number of days as a variable <em>k</em>). </li>
  </ol>
  
  <p>How do I simplify this?</p>
  
  <p>Thanks!</p>