Submit a program that starts with a function definition for factorial(n), which returns the number n! Then the main program should call that function three times to compute the number n! / ( r! * s!) of different table assignments. The program should prompt the use by "Enter the number of people" for the total number n of people, "Enter the number of chairs at table 1" to get the number r, and "Enter the number of chairs at table 2" to get s. Assume for now that r +s = n. It should then print the total number of different table assignments, preceded by the words "The number of table assignments is". This printed number should be in integer without a decimal point. This time the grading is not sensitive to white space, so extra spaces and new lines are OK (but not colons). So for the first test case, the interaction should look like:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

using python

Suppose there is a group of n people to be seated at a two tables, the first with r chairs and the second with n -r chairs. We do not care who
sits in which chair, just who sits at which table. The problem is to compute the number of different ways the people could be assigned to
tables. One way of assigning them is to make them all stand in a line, and then assign the first r people in the line to the first table, and the
remaining n-r people to the second one. The number of ways of ordering the people into a line is n! = n * (n-1) * (n-2) * ... *3* 2 * 1,
there are n possible choices for the first in line and for each of these, n - 1 choices for the second person in line, and so forth. But of these
orderings, any way of rearranging the first r people in line (of which there are r! ways) results in the same table assignment, and similarly,
each of the s! ways of rearranging the remaining s =n-r people left in line after the first r people have been seated also results in the same
table assignment. So by dividing by the two factors r! and s! to account for these repetitions of the same table assignment, we get n! / ( r! *
s!) total different table assignments.
because
Submit a program that starts with a function definition for factorial(n), which returns the number n! Then the main program should call that
function three times to compute the number n! / ( r! * s!) of different table assignments. The program should prompt the use by "Enter the
number of people" for the total number n of people, "Enter the number of chairs at table 1" to get the number r, and "Enter the number of
chairs at table 2" to get s. Assume for now that r +s = n. It should then print the total number of different table assignments, preceded by
the words "The number of table assignments is". This printed number should be in integer without a decimal point. This time the grading is
not sensitive to white space, so extra spaces and new lines are OK (but not colons). So for the first test case, the interaction should look
like:
Enter the number of people
Enter the number of chairs at table 1
3
Enter the number of chairs at table 2
The number of table assignments is 20
Transcribed Image Text:Suppose there is a group of n people to be seated at a two tables, the first with r chairs and the second with n -r chairs. We do not care who sits in which chair, just who sits at which table. The problem is to compute the number of different ways the people could be assigned to tables. One way of assigning them is to make them all stand in a line, and then assign the first r people in the line to the first table, and the remaining n-r people to the second one. The number of ways of ordering the people into a line is n! = n * (n-1) * (n-2) * ... *3* 2 * 1, there are n possible choices for the first in line and for each of these, n - 1 choices for the second person in line, and so forth. But of these orderings, any way of rearranging the first r people in line (of which there are r! ways) results in the same table assignment, and similarly, each of the s! ways of rearranging the remaining s =n-r people left in line after the first r people have been seated also results in the same table assignment. So by dividing by the two factors r! and s! to account for these repetitions of the same table assignment, we get n! / ( r! * s!) total different table assignments. because Submit a program that starts with a function definition for factorial(n), which returns the number n! Then the main program should call that function three times to compute the number n! / ( r! * s!) of different table assignments. The program should prompt the use by "Enter the number of people" for the total number n of people, "Enter the number of chairs at table 1" to get the number r, and "Enter the number of chairs at table 2" to get s. Assume for now that r +s = n. It should then print the total number of different table assignments, preceded by the words "The number of table assignments is". This printed number should be in integer without a decimal point. This time the grading is not sensitive to white space, so extra spaces and new lines are OK (but not colons). So for the first test case, the interaction should look like: Enter the number of people Enter the number of chairs at table 1 3 Enter the number of chairs at table 2 The number of table assignments is 20
Next, enhance the program for more than two tables. Keep prompting for the number of chairs at tables until the number equals n. If the
numbers of chairs at the tables are r, s, t, ., x, the reasoning above shows that the number of different assignments is n!/ (r! * s! * t! * .. * x!).
So and example interaction would be:
....
Enter the number of people
6.
Enter the number of chairs at table 1
2
Enter the number of chairs at table 2
Enter the number of chairs at table 3
The number of table assignments is 90
Finally, enhance the program so that if the number of chairs r +s+t+ ... + x after the latest user input exceeds n, the program will print
"Seating only c people at table d" where the integer d is the last table index, and the integer c = n - (r+ s+t+ . + x) is the number of people
actually needing seats at the last table, and then proceed as before, using c instead of the user-entered number x in the computation. So an
example interaction would be:
....
Enter the number of people
6.
Enter the number of chairs at table 1
Enter the number of chairs at table 2
2
Enter the number of chairs at table 3
3
Seating only 2 people at table 3
The number of table assignments is 90
Note that there is no fixed maximum number of tables for this final version of the problem; it must work for any number of tables. Therefore
you will need a while loop to keep seating people at new tables as long as there are people left unseated.
Transcribed Image Text:Next, enhance the program for more than two tables. Keep prompting for the number of chairs at tables until the number equals n. If the numbers of chairs at the tables are r, s, t, ., x, the reasoning above shows that the number of different assignments is n!/ (r! * s! * t! * .. * x!). So and example interaction would be: .... Enter the number of people 6. Enter the number of chairs at table 1 2 Enter the number of chairs at table 2 Enter the number of chairs at table 3 The number of table assignments is 90 Finally, enhance the program so that if the number of chairs r +s+t+ ... + x after the latest user input exceeds n, the program will print "Seating only c people at table d" where the integer d is the last table index, and the integer c = n - (r+ s+t+ . + x) is the number of people actually needing seats at the last table, and then proceed as before, using c instead of the user-entered number x in the computation. So an example interaction would be: .... Enter the number of people 6. Enter the number of chairs at table 1 Enter the number of chairs at table 2 2 Enter the number of chairs at table 3 3 Seating only 2 people at table 3 The number of table assignments is 90 Note that there is no fixed maximum number of tables for this final version of the problem; it must work for any number of tables. Therefore you will need a while loop to keep seating people at new tables as long as there are people left unseated.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 6 images

Blurred answer
Knowledge Booster
Troubleshooting
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education