Question: Solve TP2.2.2 again, but use NumPy to solve it for multiple values. Suppose the cover price of a book is $24.95, but bookstores get a

  • Solve TP2.2.2 again, but use NumPy to solve it for multiple values.

  • Suppose the cover price of a book is $24.95, but bookstores get a 40% discount. Shipping costs $3 for the first copy and 75 cents for each additional copy. What is the total wholesale cost for 60 copies?

  • First solve it by creating one NumPy array for each of the values in the original problem:

    24.95 40% 3 0.75 60 
  • Then add 2 more books to the order by adding 2 more numbers to each of the NumPy arrays above with these 2 sets of values:

    26.95 35% 4 1.00 70 27.95 45% 5 1.25 80 
  • Finally, create a function that accepts 4 iterables named price, discount, shipping_base, shipping_additional, and number_of_copies. The function should use the NumPy code you already wrote to return the total cost of a book order.

ques2. 3. The mathematician Srinivasa Ramanujan found an infinite series that can be used to generate a numerical approximation of 1/: 1 = 2 2 9801 k=0 (4k)!(1103 + 26390k) (k!) 43964k

  • Resolve TP7.3 by writing a function that takes k as a parameter (instead of iterating until the last term is 1e-15), uses NumPy to calculate the series quickly, and returns the estimate.
  • Use %timeit (or similar) to compare the speeds of your earlier solution's function and your new function - either changing your earlier solution's function to print the maximum value of k was when it iterated, or to stop after a specified number of iterations

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!