Python Practice Problems

  1. Write a program to make an approximation of sin(x) using the Taylor expansion of sin(x), where x is the angle in radians.
  2. Write a program that stores each number between 1500 and 2700 that is divisible by 7. The symbol in python for “modulo” is %. (x%7 would translate to “what is x modulo 7?”)
  3.  Calculate the square of each number between 0 and 27.  Print the results
  4. Write a function or routine that takes a list of item costs, finds the total, and adds 5.5% sales tax. You will provide the list of costs. Make up something that you might buy like groceries or maybe you went out to eat.
  5. Order the equations to create a decay model for “atoms” that have a lifetime of 1sec.  Start with 10 atoms.  The purpose is to see how many original “atoms” we have left after some time (1 sec).  You may need to generate some expressions yourself based on these general actions (again, these are not necessarily in order)
    1. The probability of decay is given by lambda = (np.log(2)/tau)*delta_t
    1. tau=1 #sec
    1. For each atom, compare a randomly generated number to the probability of decay. If the random number is larger than the probability of decay, then the atom has decayed. [if random_number[i] <= lambda: ]
    1. generate an array of 10 ones using np.ones((10,1)) [atoms = np.ones((10,1))]
    1. if an atom has decayed, change the value in that atom’s spot to zero (0) [atoms[i]=0]
    1. use np.random.random(10) to generate 10 random numbers between 0 and 1 [random_number = np.random.random(10)]
    1. print the “atom” array to see how many are left

If you need answers to this question, WhatsApp/Call +1 646 978 1313

Leave a Reply

Your email address will not be published.