Posts

Showing posts with the label math

Probabilities Part 1 Python Programming

Image
Problem:- Given a list of numbers and a value n, write a function that returns the probability of choosing a number greater than or equal to n from the list. The probability should be expressed as a percentage, rounded to one decimal place. Example:- probability([5, 1, 8, 9], 6) ➞ 50.0 probability([7, 4, 17, 14, 12, 3], 16) ➞ 16.7 probability([4, 6, 2, 9, 15, 18, 8, 2, 10, 8], 6) ➞ 70.0 Notes:- Precent probability of event = 100 * (num of favourable outcomes) / (total num of possible outcomes) The numbers in the list are uniformly distributed and have an equal chance of being chosen. Code:- Note:- Never miss indentation. If you are stuck check the python documentation. Suggestions and comments are always welcome.

Folding a Piece of Paper Python Programming

Image
Problem: -  Create a function that returns the thickness (in meters) of a piece of paper after folding it n number of times. The paper starts off with a thickness of 0.5mm. Example:- num_layers(1) ➞ "0.001m" # Paper folded once is 1mm (equal to 0.001m) num_layers(4) ➞ "0.008m" # Paper folded 4 times is 8mm (equal to 0.008m) num_layers(21) ➞ "1048.576m" # Paper folded 21 times is 1048576mm (equal to 1048.576m) Code:- Note:- Never miss indentation. If you are stuck check the python documentation. Suggestions and comments are always welcome.