In: Computer Science
2. An 8-digit password is required to have three 0’s and five 1’s. You will determine how many unique passwords are possible. First consider how you might notate possible outcomes in the process of listing them. For example, any of the following can represent the same outcome: 01011101 137 (the digits are the locations of the 0’s) 24568 (the digits are the locations of the 1’s) Write a program that lists and counts the unique passwords. Provide your code, all outcomes, and the count. (Python)
Look at my code and in case of indentation issues check the screenshots.
---------main.py----------------
def main():
count = 0
#We have to find position of zeroes
for i in range(0,8):
#position of first zero in a password is at
index i
for j in range(i+1,8):
#position of second zero in a password is at
index j
for k in
range(j+1,8): #position of third zero in a password is
at index k
count = count + 1 #increment
password count
password = [1]*8 #create password as
a list with all 1's
password[i] = 0
#set the position indices of zeroes with value 0
password[j] = 0
password[k] = 0
for letter in password: #print the
password
print(letter, end = "")
print()
#newline
print("Count: ", count)
#print count
main()
---------Screenshots---------------
------Output--------------
--------------------------------------
Do comment if you need any clarification.
Please let me know if you are facing any issues.
Please Rate the answer if it helped.
Thankyou