How to print the Names?

# Sample Python Project

# The President Jacob Biden decided to form a subcommittee of 4 senetors to study the Tax Evation in U.S.
# Out of 4, 2 should  be from 'Democrats' and 2 should be from 'Republicans'.
# There are 4 Democrats and 3 Rupublicans at his disposal. Find out how many ways can he form a committee.
# Democrats = ('James Smith','John Samuel','Jack Sparrow','Jay Screw')
# Republicans = ('Henry Wilson','Hally Star', 'Hill Cook')

import math

D = 4  # (Number of democrats choose from)
d = 2  # (Number of possibilities)
print('Number of combination of democrats :', math.comb(D, d))
Demo = math.comb(D, d)
R = 3  # (Number of republicans choose from)
r = 2  # (Number of possibilities)
print('Number of combination of republicans :', math.comb(R, r))
Repu = math.comb(R, r)
com = Repu * Demo
print('Number of combinations  of Republicans and Democrats in the committee : ', com)

I got the number of combinations, But how to print the names in the combinations ?

For this you would need a data-structure to actually save the combinaiton - not just calculate their number.

Then you would need a list of the names and can just print it wit print(Demo[x] + " and " + Repu[y] by using the combinations somehow saved.

All your code does right now is using a function to calculate how many combination would be possible - it does not actually create any combinations itself.

Now I got it. It does not create any combination actually.!!!
Thank you for the feed back. I have to create 18 variables to store the 18 combinations ???. But first i have to create the combinations !!Not the number. OK. I 'll try for it. I hope your continued support.

1 Like

*# This is the actual combination

De = ('James Smith; ',' John Samuel; ','Jack Sparrow; ','Jay Screw; ')
Re = ('Henry Wilson ; ','Hally Star; ', ' Hill Cook; ')
d1 = De[0]+De[1]
d2 = De[0]+De[2]
d3 = De[0]+De[3]
d4 = De[1]+De[2]
d5 = De[1]+De[3]
d6 = De[2]+De[3]
r1 = Re[0]+Re[1]
r2 = Re[0]+Re[2]
r3 = Re[1]+Re[2]
print('comb 1 :'+(d1+r1))
print('comb 2 :'+(d1+r2))
print('comb 3 :'+(d1+r3))
print('comb 4 :'+(d2+r1))
print('comb 5 :'+(d2+r2))
print('comb 6 :'+(d2+r3))
print('comb 7 :'+(d3+r1))
print('comb 8 :'+(d3+r2))
print('comb 9 :'+(d3+r3))
print('comb 10 :'+(d4+r3))
print('comb 11 :'+(d4+r1))
print('comb 12 :'+(d4+r2))
print('comb 13 :'+(d5+r1))
print('comb 14 :'+(d5+r2))
print('comb 15 :'+(d5+r3))
print('comb 16 :'+(d6+r1))
print('comb 17 :'+(d6+r2))
print('comb 18 :'+(d6+r3))

#This is a laborious work. Any suggestion for a compact code

Here are a bunch of different suggestions on how to achieve it:

to do this,enter your name between the parentheses of the “print ()” funvtion using doble quotes (since what you have to print is text)