Try below to see if that helps you, i added for finding chances of all picked are same color.
import math
#boxcount=int(input("number of boxes")) #1
totalobjects=int(input("count of objects")) #50
colorcount=int(input("no of colurs for objects in boxes")) #8-blue,13-black,29-grey
#name and count
i=0
x=[]
y=[]
while i < colorcount:
xn, yn=input("count of objects seperated by color name: ").split()
x.append(xn)
y.append(yn)
i+=1
x=list(map(int,x))
y = [element.upper() for element in y]
print(x,y) #counts of obj of each colors
xindex=0
yindex=0
pick=int(input("objects picked: "))
wantedcolor=input("function find chances of all to be --> , name the color search: ")
yindex=y.index(wantedcolor.upper())
xindex=yindex
#q1---->pick=5 chance of all blue ==> 8c5/50c5,,,
print(x[xindex])
num=x[xindex]-pick
print(num)
print(totalobjects)
den=totalobjects-pick
print(den)
if sum(x)==totalobjects:
print("chances are : ",(math.factorial(x[xindex])/math.factorial(num))/(math.factorial(totalobjects)/math.factorial(den)))
print( "----------------")
Output:
C:\Users\testuser\Downloads\DL>python test.py
count of objects50
no of colurs for objects in boxes3
count of objects seperated by color name: 8 blue
count of objects seperated by color name: 13 black
count of objects seperated by color name: 29 grey
[8, 13, 29] ['BLUE', 'BLACK', 'GREY']
objects picked: 5
function find chances of all to be --> , name the color search: blue
8
3
50
45
chances are : 2.6430553720100437e-05
----------------
C:\Users\testuser\Downloads\DL>python test.py
count of objects2
no of colurs for objects in boxes2
count of objects seperated by color name: 1 white
count of objects seperated by color name: 1 black
[1, 1] ['WHITE', 'BLACK']
objects picked: 1
function find chances of all to be --> , name the color search: white
1
0
2
1
chances are : 0.5
----------------
Best Regards,
Sandeep
GANGA SANDEEP KUMAR