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
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}")
Comments
Leave a comment