Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is a python problem and make sure there\'s no difference between the exampl

ID: 3845263 • Letter: T

Question

This is a python problem and make sure there's no difference between the example and your answer before submitting answers.

The eventual goal of this assignment is to compute the total number of ways of forming a collection of committees from an academic department of n professors The first task is to write a function called committee to compute the number of ways of forming a single committee with r members from a collection of n people. This is the same as computing the number of ways of choosing r people out of n to sit at the first of two tables, and is therefore n! (r!*(n-r)!) by the reasoning given in the zyLab in section 6.18 on seating a large group at multiple tables. Make sure the function returns an integer, not a floating point number with a decimal point In addition to the fact that this must now be a function, there there are now some further enhancements First of all, there committee membership, so there are r n! need a chairperson If so, there are r choices for the a chaired committee. Another way of ways of of the possible the for selecting is the potential that the chairperson each forming such committee of might (r! (n-r)!) ways thinking how to form such a committee is to choose the chairperson first (there are n possible choices for that), and then for each possible chairperson n-r, this gives the same final formula n! (r-1)! (n-r)!) Your function definition must be of a form like def committee (people, members, chairperson where the parameter "people" is an integer giving the number of people to choose from (called "n" in the formulas above), the parameter "members" is an integer giving the number of members in the committee (called "r in the formulas above) and the parameter "chairperson" is a boolean variable which is True if a chairperson is required, and the formula in the third paragraph of this specification must be used, and False if the committee has no chairperson, and the formula in the second paragraph must be used. You must use exactly these names for the parameters, because your function will be be called by keyword arguments using these parameter names in some of the tests, instead of just relying on the parameter order. Write your function in a file named committee.py, and upload it to zyBooks for the first few tests, which will exercise as it as a module using programs already at zyBooks that import your committee function from it. The first test is with the following calls from committee import committee committee (10, 3, True committee (10, 3, alse committee (members 3, people 10, chairperson True) committee (chairperson False embers 3, people 10) committee (2, 2, True committee (3, 3, False and the six values returned should be 360, 120, 360, 120, 2, 1 respectively. Ifthey are not all correct, zyBooks will report True for the correct ones, and False for the incorrect ones. For now, you may submit an empty file for the file multiple committees.py which will be required for later steps

Explanation / Answer

import committee

available = total_num = int(input('Enter the number of professors in the department: '))
can_or_cannot = input('Can a professor be on multiple committees? ')
total_ways = 1
chairperson = {'y': True, 'n': False}
while True:
    name_of_comt = input('Enter that name of the committee: ')
    if name_of_comt == '':
        break
    need_or_not = input('Dose the committee need a chairperson? Enter y or n: ')
    num_of_mem = int(input('Enter the number of members: '))

    if available < num_of_mem:
        num_of_mem = available
        print('Assigning only %d members to the %s committee.' % (available, name_of_comt))
    try:
        ways = committee.committee(available, num_of_mem, chairperson[need_or_not])
    except ValueError as excpt:
        print(excpt)
        continue
    total_ways *= ways
    print('There are %d ways to form the %s committee.' % (ways, name_of_comt))
    if can_or_cannot == 'n':
        available -= num_of_mem
    if available <= 0:
        break

print('There are %d ways to form all the committees.' % total_ways)

committee.py

def factorial(n):
    try:
        if n < 0:
            f = 0
            raise ValueError('Cannot take the factorial of a negative number.')
        f = 1
        for i in range(2, n+1):
            f *= i
    except ValueError as excpt:
        raise excpt
    return f

def committee(people, members, chairperson = True):
    try:
        if people <= 0:
            raise ValueError('People count must be positive.')
        if members > people:
            raise ValueError('Member count must not be greater than people count.')
        if chairperson:
    #        ways = int(factorial(members) / ((factorial(people-1))*factorial(members-people)))
            ways = int(factorial(people) / ((factorial(members-1))*factorial(people-members)))
        else:
    #        ways = int(factorial(members) / (factorial(people) * factorial(members-people)))
            ways = int(factorial(people) / (factorial(members) * factorial(people-members)))
        return ways
    except ValueError as excpt:
        raise excpt

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote