Question
python
11.8 Multiple committees The eventual goal of this assignment is to compute the total number of ways of forming a collection

from committee import committee committee (10, 3, True) committee (10, 3, False) committee (members - 3, people - 10, chairpe

(3) Now write the main program multiple committees.py, to compute the number of ways of staffing multiple committees in an ac

UI UNICI PUSe ways of forming all the multiple Committees. You can compute this number by multiplying the number of ways of f

(4) Modify the loop over the multiple committees in your main multiple_committees py program to put the call to committee() i

Note the the user gave up and entered an empty line after seeing the error, because there is no way of recovering from the er
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

1)

def factorial(n):
if n==0:
return 1
else:
return n*factorial(n-1)
def committee(people,members,chairperson):
if(chairperson):
return (factorial(people)//(factorial(members-1)*factorial(people-members)))
else:
return (factorial(people)//(factorial(members)*factorial(people-members)))
  
print(committee(10, 3, True))
print(committee(10, 3, False))
print(committee(members = 3, people = 10, chairperson = True))
print(committee(chairperson = False, members = 3, people = 10))
print(committee(2, 2, True))
print(committee(3, 3, False))

Output:

368 128 368

2)

def factorial(n):
if n<0:
raise ValueError("Cannot take the factorial of a negative number")
if n==0:
return 1
else:
return n*factorial(n-1)
  
def committee(people,members,chairperson=True):
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):
return (factorial(people)//(factorial(members-1)*factorial(people-members)))
else:
return (factorial(people)//(factorial(members)*factorial(people-members)))
  

print(committee(10, 3))
print(committee(members = 3, people = 10))
print(committee(2, 2))

Output:

368 368

3,4,5)

committee.py:

def factorial(n):
if n<0:
raise ValueError("Cannot take the factorial of a negative number")
if n==0:
return 1
else:
return n*factorial(n-1)
  
def committee(people,members,chairperson=True):
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):
return (factorial(people)//(factorial(members-1)*factorial(people-members)))
else:
return (factorial(people)//(factorial(members)*factorial(people-members)))


multiple_committees.py

from committee import committee
professors=int(input("Enter the number of professors in the department:"))
canProfessorOnMultipleCommittee=input("Can a professor be on multiple committees? Enter y or n:")
TotalNoOfWays=1

while(True):
committeeName=input("Enter that name of the committee:")
if(not committeeName):
break
needChairPerson=input("Does the committee need a chairperson? Enter y or n:")
members=int(input("Enter the number of members:"))
if(professors<members and professors>0):
print("Assigning only ",professors,"members to the ",committeeName," committee.")
print("There are ",professors," ways to form the ",committeeName," committee.")
TotalNoOfWays*=professors
break
try:
if(needChairPerson=='n'):   
noOfWays=committee(professors,members,False)
else:
noOfWays=committee(professors,members)
TotalNoOfWays*=noOfWays
print("There are ",noOfWays," ways to form the ",committeeName," committee.")
if(canProfessorOnMultipleCommittee=='n'):
professors=professors-members
except ValueError as e:
print(e)
print("There are ",TotalNoOfWays," ways to form all the committees.")   

SCREENSHOTS OF THE CODE SHOWN BELOW:

1 #committee.py 2 def factorial(n): if n<: raise ValueError(Cannot take the factorial of a negative number) if n==0: return

20 #multiple_commitees.py 21 #from committee import committee 22 professors=input(Enter the number of professors in the depa

Output:

Enter the number of professors in the department:12 Can a professor be on multiple committees? Enter y or niy Enter that name

Enter the number of professors in the department: -2 Can a professor be on multiple committees? Enter y or n:n Enter that nam

Enter the number of professors in the department:5 Can a professor be on multiple committees? Enter y or n:n Enter that name

HOPE YOU SATISFIED WITH THE ANSWER.PLEASE GIVE POSITIVE RATINGS.THANKYOU....!!!!

Add a comment
Know the answer?
Add Answer to:
python 11.8 Multiple committees The eventual goal of this assignment is to compute the total number...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 8. Exercise: Counting committees Bookmark this page Exercise: Counting committees 0.0/2.0 points (graded) We start with...

    8. Exercise: Counting committees Bookmark this page Exercise: Counting committees 0.0/2.0 points (graded) We start with a pool of n people. A chaired committee consists of k 1 members, out of whom one member is designated as the chairperson. The expression k(can be interpreted as the number of possible chaired committees with k members. This is because we have choices for the k members, and once the members are chosen, there are then k choices for the chairperson. Thus, is...

  • Using python 3.6 How do I incorporate 0 or negative input to raise an error and...

    Using python 3.6 How do I incorporate 0 or negative input to raise an error and let the user try again? like <=0 #loop to check valid input option. while True: try: choice = int(input('Enter choice: ')) if choice>len(header): print("Invalid choice!! Please try again and select value either:",end=" ") for i in range(1,len(header)+1): print(i,end=",") else: break choice = int(input('\nEnter choice: ')) except ValueError as ve:print('Invalid response, You need to select the number choice from the option menu') # Catch your...

  • This is Python The program should accept input from the user as either 7-digit phone number...

    This is Python The program should accept input from the user as either 7-digit phone number or 10-digit. If the user enters 7 characters, the program should automatically add "512" to the beginning of the phone number as the default area code. Dash (hyphen) characters do not count in input character count, but must not be random. If the user enters dashes the total character count must not exceed 12. The program should not crash if the user enters invalid...

  • 15to25 15.How many ways are there to seat ten people around a circular table where two seatings are considered the s...

    15to25 15.How many ways are there to seat ten people around a circular table where two seatings are considered the same when every one has the same immediate left and immediate right neighbor? 16.In how many ways can a photographer at a wedding arrange six people in a row, including the bride and groom, if a) the bride must be next to the groom? b) the bride is not next to the groom? 17.How many bit strings of length seven...

  • Could anyone help add to my python code? I now need to calculate the mean and...

    Could anyone help add to my python code? I now need to calculate the mean and median. In this programming assignment you are to extend the program you wrote for Number Stats to determine the median and mode of the numbers read from the file. You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The...

  • -can you change the program that I attached to make 3 file songmain.cpp , song.cpp ,...

    -can you change the program that I attached to make 3 file songmain.cpp , song.cpp , and song.h -I attached my program and the example out put. -Must use Cstring not string -Use strcpy - use strcpy when you use Cstring: instead of this->name=name .... use strcpy ( this->name, name) - the readdata, printalltasks, printtasksindaterange, complitetasks, addtasks must be in the Taskmain.cpp - I also attached some requirements below as a picture #include <iostream> #include <iomanip> #include <cstring> #include <fstream>...

  • 12.8 GPA reports using files This program is to compute and write to a file the...

    12.8 GPA reports using files This program is to compute and write to a file the GPA for student scores read from an input file. As in Lab 7.5, the point values of the grades are 4 for A, 3 for B, 2 for C, 1 for D, and 0 for F. Except for the grade A, where + has no effect, a + after the letter increases the point value by 0.3, and except for F, where a -...

  • Assignment Overview In Part 1 of this assignment, you will write a main program and several...

    Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...

  • I need to get this two last parts of my project done by tonight. If you...

    I need to get this two last parts of my project done by tonight. If you see something wrong with the current code feel free to fix it. Thank you! Project 3 Description In this project, use project 1 and 2 as a starting point and complete the following tasks. Create a C++ project for a daycare. In this project, create a class called child which is defined as follows: private members: string First name string Last name integer Child...

  • For this assignment, write a program that will generate random numbers in the range of 50-100...

    For this assignment, write a program that will generate random numbers in the range of 50-100 and count how many fall into particular ranges. Processing: The program should first seed the random number generator. This is done one time in the program. Use srand(0). Next, generate and display a series of 10 random numbers between 50 and 100. There are several ways to ensure that a random number falls between 50 and 100. One possibility is to use the following...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT