If the circle in centered at (0,0) and has a radius if 1, the
length of the side of the square is 2.
The area of the circle is π r2= π and the
area of the square is 2 r2=4. The ratio of
the area of the circle to the area of the square is π/4.
This suggests a method to compute π. If we compute the ratio of the area of the circle to the area of the square and multiply the result by 4 we have the value of π.
To compute this ratio we use a Monte Carlo method, which is method that uses a sequence of random numbers. Suppose we select a random point (x,y) with [-1 ≤ x ≤ 1] and [-1 ≤ y ≤ 1] and we check if the point is in the circle or in the part of the square outside the circle. If we repeat this geneartion of points many times, the ratio of the number of points that are outside the circle to the number of points that are inside the circle is a good approximation of π/4. The accuracy of the results depends on the number of points used. More points produce a more accurate value.
To use the Monte Carlo method described above, you need to generate points by generating random numbers in the [-1, 1] range. For each point, you need to check if the point is inside the circle or not (recall that the parametric form of a circle is x2 +y2 = r) and determine if the point falls within the circle or not. Try various sample sizes, including 100, 1,000, 100,000 and 1,000,000 and observe how the sample size affects the accuracy of the result. Compare your result with the value that python has for π , which is defined in the math module
from math import * pi
To generate random numbers in python, you need to import the random module. Use
uniform(-1,1)to generate a randonm number in the [-1,1] range.
Start by writing a program to determine the score of a BlackJack hand. First you need to decide how to represent the values of the cards (as characters or integers). Next, how to represent a hand (as a listi, for instance). Given a hand of cards compute its value if less than 21. Since the Ace Ace can count as either 1 or 11. you should initially value any Ace as 11 unless the total of the hand is greater than 21. If the value of the hand is greater than 21, you should recompute it assuming the Ace(s) is (are) valued as 1.
Next create a deck of cards, each with value and suite (for instance, using a list). You need to shuffle the deck, which you can do using another function from the random module, shuffle(x), where x is a sequence.
Write a Python program that reads a genome as a string and displays all the
genes in the genome. Note
that that finding a substring matching an end codon but which overlaps two codons
would not be an actual
end codon (i.e., the resulting gene string should be divisible by three).
Example:
Enter a DNA sequence: TCATGTGCCCAAGCTGACTATGGCCCAATAGCG Gene 1 TGCCCAAGC Gene 2 GCCCAAThis is just the beginning to having fun with DNA problems.