Python number game with changing feeback
Question: User guesses four digit number and feedback needs to be 'F' if a number is
correct but not in the right place, 'X' if the number is not in the number at
all and if the digit is correct and in the right position it displays the
digit. Code below shows my attempt but it is giving me the error: expected str
instance, list found

    
    
    from random import randint
    
    
    def check_char(a, b):   #Function making output display F, number and X depending on user input
    
        if a == b:
            return randomNumber         #Number is displayed when correctly guessed
        elif b == randomNumber:
            return 'F'                  #F means number is somewhere in the randomNumber
        elif b != randomNumber:
            return 'X'                  #X means number is nowhere in the randomNumber
    
    guessesTaken = 1
    
    randomNumber = [str(randint(1, 9))  for _ in range(4)] # create list of random nums
    print(randomNumber)
    
    while guessesTaken < 10:
    
        guesses = list(input("Guess Number: ")) # create list of four digits
        check = ''.join([check_char(int(a), int(b)) for a, b in zip(guesses, randomNumber)])
        if check == "YYYY": # if check has four Y's we have a correct guess
            print("Congratulations, you are correct, it took you", guessesTaken, "guesses.")
                break
        else:
            guessesTaken += 1 # else increment guess count and ask again
                print(check)
        if guessesTaken == 10:
            print("You lose")
    


Answer: You will be replacing X with F if the user has guessed a number and it is in
randomNumber at another position it will be replaced with an ``F:

    
    
    from random import randint    
    
    guessesTaken = 1
    
    randomNumber = [str(randint(1, 9))  for _ in range(4)] # create list of random nums
    
    def check_char(a, b):   #Function making output display F, number and X depending on user input
        if a == b:
            return b        #Number is displayed when correctly guessed
        elif a in randomNumber and a != b: # if 
            return 'F'                  
        elif a != b:
            return 'X'
    while guessesTaken < 10:
    
        guesses = list(raw_input("Guess Number: ")) # create list of four digits
        check = ''.join([check_char(a, b) for a, b in zip(guesses, randomNumber)])
        if check.isdigit(): # if check is all digits, number is guessed
            print("Congratulations, you are correct, it took you", guessesTaken, "guesses.")
            break
        else:
            guessesTaken += 1 # else increment guess count and ask again
            print(check)
    else:
        print("You lose")
    

You don't need to cast as ints in `check_char(a, b)` as strings will compare
just fine `"1" == "1" is True`

You are returning the list `return randomNumber` not the substring `b` so you
get an error trying to `join` as it expects a string not a list, also `b`
would never be equal to `randomNumber` .

