I am a complete beginner at learning python 3. I came across a problem. Please take a look at the code within the three stars:
s = input("Enter the value of N A B with white space in between ")
N, A, B=list(s.split())
def input_for_faces(*args):
NumberOfA=0
NumberOfB=0
for x in args:
if x == int(A):
NumberOfA += 1
for y in args:
if y == int(B):
NumberOfB += 1
listAB=[NumberOfA, NumberOfB]
return listAB
# ***
var=input("Enter the values on the faces of the cube seperated by commas ")
NA, NB=input_for_faces(var)
print(input_for_faces(var))
# ***
print("The probability of the chef winning is "+str((int(NA)/int(N)*(int(NB)/int(N))))
This method of input for *args
didn't give the right output(It worked but gave wrong answer). But when I gave direct values for args, the program worked correctly.
Direct input refers to:
s = input("Enter the value of N A B with white space in between ")
N, A, B=list(s.split())
def input_for_faces(*args):
NumberOfA=0
NumberOfB=0
for x in args:
if x == int(A):
NumberOfA += 1
for y in args:
if y == int(B):
NumberOfB += 1
listAB=[NumberOfA, NumberOfB]
return listAB
# ***
NA, NB=input_for_faces(1,1,1,1,1)
# ***
print("The probability of the chef winning is "+str((int(NA)/int(N))*(int(NB)/int(N))))
Please tell me what I did wrong.