Answer to Question #334869 in Python for Sin

Question #334869

Rahul is playing a guessing number game with computer. The objective of the game is to guess the number that computer thinks. A guess is correct when the guess exactly matches with computer number. After each guess by rahul, the computer will give a score comprising of black and white coins.


Black coin== guessed digit is present in the computer number and in same position


White coin== guessed digit is present but in another position..


Your task is to find out the no.of black and no.of.white coins.


Input: first line contains two space seperated integers denoting rahuls guess and computer number.



Input1: 1423 1234


Output: black: 1 white: 3


Input2: 1423 5678


Output: black:0 white: 0



Need correct output sir

1
Expert's answer
2022-04-28T13:21:47-0400
str = input("Input: ").split()
str1 = str[0]
str2 = str[1]
black = 0
print("Output:")
for i in range(len(str1)):
    if str1[i] == str2[i]:
        black += 1
white = 0
for i in range(len(str1)-1):
    for j in range(len(str1)):
        if str1[i] == str2[j]:
            white += 1
if (white == 0) & (black == 0):
    print(f"black: {black} white: {white}")
    print("Need correct output sir")
else:
    print(f"black: {black} white: {white}")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS