In probability theory, one problem that often arises is determining the number of ways in which...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
In probability theory, one problem that often arises is determining the number of ways in which p objects can be selected from a distinct objects without regard to the order in which they are selected. Such selections are called combinations. The number of combinations of p objects from a set with n objects is C (n.p) and is given by: n! C(n. p): (n-p)! p! Write a Python program which will calculate and display on the screen the number of possible combination C based on the values of n and p; where both n and p are positive integers less than 21 and n>p. Implement and use at least the following three functions: fact(...): A function when passed a positive integer value, will calculate and return the factorial of that number. . comb(...): A function when passed n and p (n: total number of objects and p: number of objects taken at a time) will calculate and return the total number of possible combinations (using the formula above). It calls function fact(...) main(...): reads and validates the values of n and p, calls function comb(...) and prints the result. Enter n and p each in range [0,20] and n>p: -8 10 Invalid Input, try again Enter n and p each in range [0,20] and n>p: 5-6 Invalid input, try again Enter n and p each in range [0,20] and n>p: 51 8 Invalid input, try again Enter n and p each in range [0,20] and n>p: 9 17 Invalid input, try again Enter n and p each in range [0,20] and n>p: 86 Number of combinations c(8,6)= 28 Figure 1. Exercise 1 Sample Run In probability theory, one problem that often arises is determining the number of ways in which p objects can be selected from a distinct objects without regard to the order in which they are selected. Such selections are called combinations. The number of combinations of p objects from a set with n objects is C (n.p) and is given by: n! C(n. p): (n-p)! p! Write a Python program which will calculate and display on the screen the number of possible combination C based on the values of n and p; where both n and p are positive integers less than 21 and n>p. Implement and use at least the following three functions: fact(...): A function when passed a positive integer value, will calculate and return the factorial of that number. . comb(...): A function when passed n and p (n: total number of objects and p: number of objects taken at a time) will calculate and return the total number of possible combinations (using the formula above). It calls function fact(...) main(...): reads and validates the values of n and p, calls function comb(...) and prints the result. Enter n and p each in range [0,20] and n>p: -8 10 Invalid Input, try again Enter n and p each in range [0,20] and n>p: 5-6 Invalid input, try again Enter n and p each in range [0,20] and n>p: 51 8 Invalid input, try again Enter n and p each in range [0,20] and n>p: 9 17 Invalid input, try again Enter n and p each in range [0,20] and n>p: 86 Number of combinations c(8,6)= 28 Figure 1. Exercise 1 Sample Run
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
Portray in words what transforms you would have to make to your execution to some degree (a) to accomplish this and remark on the benefits and detriments of this thought.You are approached to compose...
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
In recent years, Avery Transportation purchased three used buses. Because of frequent turnover in the accounting department, a different accountant was in charge of selecting the depreciation method...
-
(a) Explain the difference between a contractual interest rate and market interest rate. (b) Explain why one rate changes over the term of the bonds and the other stays the same.
-
Natalia, a resident of Canada, owns 100% of the shares of New Age Limited (NAL). NAL carries on scientific research and experimental development (SR&ED) activities with respect to finding the...
-
If the rate of change of force with respect to displacement, \(d f / d x\), is a decreasing function of \(k\), the spring is called a a. soft spring b. hard spring c. linear spring
-
In Integrative Case 10.1, we projected financial statements for Starbucks for Years +1 through +5. In this portion of the Starbucks Integrative Case, we use the projected financial statements from...
-
5. Create a flowchart that shows how to log in an account in social media (Facebook page) using a correct user-defined User ID and Password. (15 pts.) Legends: EmailID = Email ID pass = password
-
Hai Vu is the new president of Pacific Coast Optics (PCO) a small manufacturing firm in Sacramento, CA which produces fiber lenses for Street Mapping System, Infrared Lens for Anti-Terrorism...
-
Using Mapquest (http://www.mapquest.com) find the mileage between all the cities, you will build a mileage chart for cities in the state of California. Use California with the cities of Auburn,...
-
4. The result of a sieve analysis for a soil sample is given in Table 1. The soil does not exhibit any plastic behavior when water is added to it. a. Plot the grain size distribution curve. You...
-
A 1.5-in.-diameter steel shaft of length 4 ft will be used to transmit 60 hp between a motor and a pump. Knowing that G = 11.2 x 106 psi, determine the lowest speed of rotation at which the stress...
-
1. State the basic postulates of relativity and derive the L.T. 2. What do you understand by space contraction? Derive the formula for it. 3. What is time dilation? How does it arise from...
-
TLC of Known Compounds Complete the table below (include calculations, use additional page as necessary) Compound Experimental Rf Aspirin Ibuprofen Acetaminophen Caffeine 0.60 0.58 0.625 0.375...
-
What is the modulus of the resultant force, which when acting on a 5 kg mass produces a modulus acceleration 1.8 m / s2 per plane with an angle of inclination of 35 ?
-
What is the shape of the exponential distribution?
-
Use Romberg integration to compute R3,3 for the following integrals. (cos a)2 dx 0.75 x In(x 1) dx ((sin x) - 2xsinx 1) dx 212 le dx x Inx
-
Use each of the Adams-Bashforth methods to approximate the solutions to the following initial-value problems. In each case use starting values obtained from the Runge-Kutta method of order four....
-
Suppose the n n matrix A has eigenvalues 1, . . . , n ordered by |1| > |2| > |3| |n|, with linearly independent eigenvectors v(1), v(2), . . . , v(n). a. Show that if the Power method is applied...
-
Derive the stiffness matrix of each of the systems shown in Figs.6.21 using the indicated coordinates. Pulley, mass M, mass moment of inertia Jo 2k k 3r 000 0 3m x1(t) F(t) I x2(t) m T x3(t) F2(t) 3k...
-
A simplified model of the main landing gear system of a small airplane is shown in Fig. 6.27 with \(m_{1}=100 \mathrm{~kg}, m_{2}=5000 \mathrm{~kg}, k_{1}=10^{4} \mathrm{~N} / \mathrm{m}\), and...
-
Derive the stiffness matrix of each of the systems shown in Figs. 6.18 using the indicated coordinates. F(t) 5k 0000 m2 F2(t) m1 k k x1(t) F3(t) 00000 m3 k k x(1) X3(1) FIGURE 6.18...
Study smarter with the SolutionInn App